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

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

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


当前回答

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

在manifest.xml文件中:

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

其他回答

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

结果如下:

简单地改变你的应用主题的父标签为" theme . appcompat . light . noactionbar "

在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.view.Window的导入。

package com.hoshan.tarik.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
    }
}

隐藏标题和动作栏我这样做:

在Manifest的activity标签中:

android:theme="@style/AppTheme.NoActionBar"

在Activity.java setContentView之前:

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

也就是说,

//删除标题栏

this.requestWindowFeature (Window.FEATURE_NO_TITLE);

//删除通知栏

this.getWindow () .setFlags (WindowManager.LayoutParams。FLAG_FULLSCREEN WindowManager.LayoutParams.FLAG_FULLSCREEN);

注意:你需要在setContentView之前保留这些行