Android隐藏Activity的标题栏和状态栏

一、隐藏标题栏,两种方式

1、更换activity主题(theme)

在应用清单文件(AndroidManifest.xml)中找到对应的activity标签,设置activity的theme属性,值为任一带有NoActionBar的主题,如

附:

android:theme="@android:style/Theme.AppCompat.NoActionBar" 不显示应用程序标题栏 
android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏 
android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏 
android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏 
android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏 
android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏 
android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏 
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏 
android:theme="Theme.Translucent.NoTitleBar" 透明背景并无标题
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 透明背景并无标题,全屏

以上是常见的无标题栏主题,当然你也可以自定义主题。。。

2、通过代码控制

(1)activity继承Activity

在onCreate()之后,setContentView()之前,加入

requestWindowFeature(Window.FEATURE_NO_TITLE); 

 (2)activity继承AppCompatActivity

在onCreate()方法中使用

getSupportActionBar().hide()

二、隐藏状态栏

在activity中使用

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

猜你喜欢

转载自blog.csdn.net/qq_54087555/article/details/126876361