我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。

使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。

我可以在某个地方设置无标题样式的项目吗?


当前回答

第一个答案是角闪石。 以下是我的解释: 添加:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

在oncreate()方法中。

之前:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);

(不仅仅是在setContentView之前) 如果不这样做,你将被强制关闭。 +1这个答案。

其他回答

在onCreate方法中,使用以下代码段:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

在onCreate()方法中执行此操作。

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here); 

这是指活动。

在我的例子中,如果你使用的是android studio 2.1,并且你的编译SDK版本是6.0,那么只需转到你的manifest.xml文件,并更改以下代码:

代码如下:

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

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

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

</manifest>

下面是截图(见高亮代码):

您可以在java文件中使用此代码

在设置或加载视图之前添加这一行

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main);

Add

<item name=“android:windowNoTitle”>true</item>

在AppTheme内部(style .xml)