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

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

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


当前回答

我正在使用Android Xamarin,这对我来说很有效。

SupportActionBar.Hide();
SetContentView(Resource.Layout.activity_main);

其他回答

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

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

添加舱单文件,

  android:theme="@android:style/Theme.Translucent.NoTitleBar"

添加以下行到您的Java文件,

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);

标题栏可以用两种方式删除,如开发者Android页面所述:

在manifest.xml文件中:

如果你想为应用程序中的所有活动删除它,请在应用程序中添加以下内容: <应用android:主题= " @android:风格/ Theme.Black.NoTitleBar”> 或用于某一特定活动: <活动android:主题= " @android:风格/ Theme.Black.NoTitleBar”>

现在我做了以下事情。

我声明了一个样式,继承了我的通用样式的所有内容,然后禁用了标题栏。

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>

现在我可以将此样式设置为我想要隐藏标题栏的每个活动,覆盖应用程序范围的样式并继承所有其他样式信息,因此在样式代码中没有重复。

要将样式应用到特定的Activity,打开AndroidManifest.xml并将以下属性添加到Activity标签中;

<activity
    android:theme="@style/generalnotitle">

对于AppCompat,以下解决方案对我来说是有效的:

在你的styles.xml中添加新的没有操作栏的主题样式,并设置parent=" theme . appcompat . noactionbar "。

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>

现在在androidManifest.xml中为你的启动画面活动实现相同的主题样式

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 

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

结果如下: