当前位置: 移动技术网 > IT编程>移动开发>Android > Android 去掉状态栏的方法汇总

Android 去掉状态栏的方法汇总

2019年07月24日  | 移动技术网IT编程  | 我要评论

β-谷甾醇,纳米蛊,色爱综合网欧美Av

在实际的应用程序开发中,我们有时需要把 activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果:

其一,通过在代码中可以设置,

其二,通过manifest配置文件来设置全屏。

其一:在代码oncreate里面setcontentview之前设置(如下)

view plaincopy to clipboardprint?
public void oncreate(bundle savedinstancestate) { 
super.oncreate(savedinstancestate); 
//取消标题 
requestwindowfeature(window.feature_no_title); 
//取消状态栏
getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, 
windowmanager.layoutparams.flag_fullscreen); 
setcontentview(r.layout.main); 
}

但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在 setcontentview(r.layout.main)(界面渲染,完成了再全屏是不行的)这段代码的前面。要不然会报错。

其二:在manifest配置文件中设置

第一种方法

①在res/values 目录创建个theme.xml文件(用来放样式)

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<!-- name 是style的名称,parent 继承那个父类样式 --> 
<style name="theme_fullscreen" parent="android:theme.black"> 
<item name="android:windownotitle">true</item> <!-- 设置无标题 --> 
<item name="android:windowfullscreen">?android:windownotitle</item> <!-- 是否填充慢屏幕,引用android:windownotitle 的值 ?android:windownotitle,取决于android:windownotitle的值-->
</style> 
</resources>

②<activity android:name=".login.loginactivity" android:theme="@style/theme_fullscreen"/>

第二种方法

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.andyidea" 
android:versioncode="1" 
android:versionname="1.0"> 
<uses-sdk android:minsdkversion="8" /> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
<activity android:name=".login.loginactivity" 
android:theme="@android :style/theme.notitlebar.fullscreen" 
android:label="@string/app_name"> 
<intent-filter> 
<action android:name="android.intent.action.main" /> 
<category android:name="android.intent.category.launcher" /> 
</intent-filter> 
</activity> 
</application> 
</manifest> 

只去程序标题栏 设置整个应用 no title

第三种:这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件例如:

<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="theme_notitle"> <item name="android:windownotitle">true</item> </style> </resources>

这样,我们就自定义了一个style,就相当于一个主题,然后在androidmanifest.xml文件中定义

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/theme_notitle">

这样也可以达到去掉标题栏的效果

以上给大家总结了三种android去掉状态栏的方法,希望本文所述能够帮助到大家。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网