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

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

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


当前回答

只需使用getActionBar().hide();在你的主活动onCreate()方法中。

其他回答

将此样式添加到style.xml文件中

 <style name="AppTheme.NoActionBar">
     <item name="windowActionBar">false</item>
     <item name="windowNoTitle">true</item>
 </style>

之后,在你不想看到标题栏的特定活动中引用此样式名称到androidManifest.xml,如下所示。

<activity android:name=".youractivityname"
     android:theme="@style/AppTheme.NoActionBar">
</activity>

你可以修改AndroidManifest.xml:

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

或者使用android:theme="@android:style/ theme . black。NoTitleBar"如果你不需要全屏活动。

注意:如果你之前使用了一个'default'视图,你可能也应该把父类从AppCompatActivity改为Activity。

当我尝试使用那些高赞的答案时,我的应用程序总是崩溃。 (我想这和“@android:style”有关吧?)

对我来说,最好的解决方案是使用以下方法:

android:theme="@style/Theme.AppCompat.NoActionBar"

不再有标题栏。只要把它放在<应用程序>…</application>或<activity>…</activity>取决于你是否(不)想要它在整个应用程序或只是一个特定的活动。

在我的例子中,如果你使用的是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>

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

为你使用的主题添加这两个:

    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>