我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
这解决了我的问题
在表现我的活动:
<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>
其他回答
我使用的是支持小部件Toolbar v7。 因此,为了能够删除或隐藏标题,我们需要这样写。
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
//Remove¡ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
Add
<item name=“android:windowNoTitle”>true</item>
在AppTheme内部(style .xml)
在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);
这是指活动。
我发现了发生这种错误的两个原因。
一个。窗口标志已经在super.onCreate(savedInstanceState)中设置好了;在这种情况下,您可能需要使用以下命令的顺序:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
两个。在标题栏中有Back/Up按钮,这意味着当前活动是另一个活动的分层子活动,在这种情况下,您可能想要注释掉或从onCreate方法中删除这行代码。
getActionBar().setDisplayHomeAsUpEnabled(true);
添加主题@style/ theme . appcompat . light。在AndroidManifest.xml中的NoActionBar
<activity
android:name=".activities.MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>