java - 无法隐藏标题栏

标签 java android titlebar

我是 Android 开发新手,我想在我的应用程序中隐藏标题栏。

我尽了一切努力来隐藏该栏,但应用程序要么停止了,要么没有任何变化。

我在虚拟设备上运行了演示。这是一部 5.4 英寸 FWVGA 手机。
我还尝试添加
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"

android:theme="@android:style/Theme.NoTitleBar(.Fullscreen)"
但不幸的是,应用程序停止了。

请告诉我如何隐藏标题栏。
这是我的java代码,布局文件,AndroidManifest.xml和styles.xml。

package com.activitytest2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //1.   getActionBar().hide();
    //2.   requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.first_layout);
    Button button1 = (Button) findViewById(R.id.button_1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(FirstActivity.this,"You clicked button 1",Toast.LENGTH_SHORT).show();
        }
    });
}

}

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/button_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="button 1"/>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.activitytest2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".FirstActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
 </resources>

最佳答案

走简单的路。只需替换 getActionBar().hide();getSupportActionBar().hide();

希望这个解决方案对您有所帮助。

"@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();       
    setContentView(R.layout.first_layout);"

关于java - 无法隐藏标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38346830/

相关文章:

java - Lambdaj:遍历 Map 并获取值并放入其他 Map

java - 如何通过加入来持久化实体?

Android RoomDatabase - 无法解析 android.arch.persistence.room :compiler:1. 0.0

android - 如何为 ListView 中的单个元素设置动画

android - 是否可以在 Android 上运行静态链接的 ELF 二进制文件?

java - JSONObject 返回类型

java - oAuth2 clientId 和 clientSecret 的正确位置

c# - 有没有一种简单的方法来确定用户标题栏中使用的字体?

java - 如何删除框架的 Activity 标题栏?

cmd - 从命令提示符启动时更改应用程序的标题