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

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

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


当前回答

在这篇文章中提到了它,但没有人明确地解决它,所以这可能会节省人们一些时间。如果你像我一样,有多个类扩展了一个扩展ActionBarActivity的根类,可能不会立即明显地尝试将该活动设置为NoTitleBar/NoActionBar会抛出一个错误,具体来说:

“你需要使用一个主题。AppCompat主题(或后代)

你可以修改扩展到活动。

其他回答

如果你做用户YaW和Doug Paul说的,那么你必须记住在调用setContentView之前必须设置窗口特性。如果不是,您将得到一个异常。

在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); 

这是指活动。

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

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这个答案。

在这篇文章中提到了它,但没有人明确地解决它,所以这可能会节省人们一些时间。如果你像我一样,有多个类扩展了一个扩展ActionBarActivity的根类,可能不会立即明显地尝试将该活动设置为NoTitleBar/NoActionBar会抛出一个错误,具体来说:

“你需要使用一个主题。AppCompat主题(或后代)

你可以修改扩展到活动。

这解决了我的问题

在表现我的活动:

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

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

在“AppTheme”名称下的样式:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme"
        parent="Theme.AppCompat.Light.NoActionBar">
        **<item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>**
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>