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

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

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


当前回答

在我的例子中,我的活动是扩展AppCompatActivity。

class MyActivity: AppCompatActivity(){
    ...
}

所以,其他答案都不管用。 我必须这样做:

class MyActivity: AppCompatActivity(){
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
}

它确实有效!

如果你的活动扩展了AppCompatActivity,只要在requestWindowFeature(…)之前添加“support”即可。

其他回答

添加主题@style/ theme . appcompat . light。在AndroidManifest.xml中的NoActionBar

<activity
        android:name=".activities.MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    </activity>

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

这是指活动。

我相信,在2020年,这个问题只有一个答案

将以下行添加到styles.xml中

<item name="windowNoTitle">true</item>

对于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>

结果如下:

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

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