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

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

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


当前回答

我更喜欢:-

AppTheme(整个应用程序主题) AppTheme。NoActionBar(没有操作栏或工具栏的主题) fullscreen(没有动作栏和状态栏的主题)

主题风格喜欢:-

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorDarkPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

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

<style name="AppTheme.NoActionBar.FullScreen" parent="AppTheme.NoActionBar">
    <item name="android:windowFullscreen">true</item>
</style>

在onCreate方法中也把下面的代码放在super.onCreate(savedInstanceState)之后

super.onCreate(savedInstanceState)    
this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)

其他回答

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

这是指活动。

正确的答案可能是不扩展ActionbarActivity,而只是扩展Activity


如果你仍然使用动作栏活动 这似乎起作用了:

@Override
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //<< this
    setContentView(R.layout.activity_main);
}

这似乎也管用:

styles.xml:

   <style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
          <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

我可以像斯科特·比格斯写的那样。这种方法很有效。除了没有主题。我的意思是设置菜单的背景是透明的:

只改变

public class MainActivity extends ActionBarActivity {

到Activity或FragmentActivity

public class MainActivity extends Activity  {

然而,我可以让它看起来足够好使用材料设计,而不是删除 actionbar: https://gist.github.com/shimondoodkin/86e56b3351b704a05e53

设置应用程序图标 设置操作栏的颜色以匹配设计。 将图标设置为设置菜单 添加更多图标(顶部按钮)

它是通过实例的材料设计兼容动作栏样式。

这解决了我的问题

在表现我的活动:

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

现在我做了以下事情。

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

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

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

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

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

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

在manifest.xml文件中:

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