首页 > 系统 > Android > 正文

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

2019-10-22 18:24:02
字体:
来源:转载
供稿:网友

Android Studio在实现android/226986.html">隐藏标题栏和状态栏上和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实现标题栏和状态栏的隐藏,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对VEVB武林网网站的支持!

 

注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表