我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
添加舱单文件,
android:theme="@android:style/Theme.Translucent.NoTitleBar"
添加以下行到您的Java文件,
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
其他回答
WindowManager。LayoutParams在Android Studio文档说FLAG_FULLSCREEN是“窗口标志:隐藏所有的屏幕装饰(如状态栏),而这个窗口显示。”所以这个标志不会让我的内容充满整个屏幕。
只需使用getActionBar().hide();在你的主活动onCreate()方法中。
这解决了我的问题
在表现我的活动:
<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>
这是完整代码的样子。注意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);
}
}
如果你替换了DarkActionBar的定义,你只需要改变style .xml中的AppTheme样式
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
对NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
在androidmanifest .xml中定义的AppTheme