Android Studio实现标题栏和状态栏的隐藏

时间:2022-07-28
本文章向大家介绍Android Studio实现标题栏和状态栏的隐藏,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Android Studio在实现隐藏标题栏和状态栏上和Eclipse是完全不一样的。

在Eclipse上隐藏标题栏和状态栏的代码如下:

方法一: requestWindowFeature(Window.FEATURE_NO_TITLE);

方法二:getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

今天在做闪屏页开发时,想把标题栏和状态栏隐藏掉,但这两种方法尝试后都不行。

最后的解决方案:

①先在values的styles.xml中添加子标签:

<style name="NoTitle" parent="Theme.AppCompat.DayNight.NoActionBar"  
 <item name="android:windowNoTitle" true</item  
 <item name="android:windowFullscreen" true</item  
</style  

②在清单文件中,需要隐藏标题栏和状态栏的Activity引用此样式:

<activity android:name=".SplashActivity" android:theme="@style/NoTitle"  

经过这两步,便是一个没有标题栏和状态栏的完美闪屏页了!

PS:下面看下Android Studio 去掉标题栏状态栏的完整代码

**网上关于Android Studio的教程比较少,去掉标题栏的方法大多不能直接使用。

在Android Studio中其实更简单一些,在app/res/values/styles.xml文件中加个标签就可以了**

<item name="windowNoTitle" true</item  

完整代码如下,可以看到这段代码放在什么位置。

 <resources  
  <!-- Base application theme. --  
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"  
   <!-- Customize your theme here. --  
   <item name="colorPrimary" @color/colorPrimary</item  
   <item name="colorPrimaryDark" @color/colorPrimaryDark</item  
   <item name="colorAccent" @color/colorAccent</item  
   <item name="windowNoTitle" true</item  
  </style  
 </resources  

加到 加载视图前面

//取消状态栏
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 WindowManager.LayoutParams.FLAG_FULLSCREEN);

总结

以上所述是小编给大家介绍的Android Studio实现标题栏和状态栏的隐藏,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对ZaLou.Cn网站的支持!