Android 去掉状态栏的方法汇总

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

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

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

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

?
1
2
3
4
5
6
7
8
9
10
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文件(用来放样式)

?
1
2
3
4
5
6
7
8
<?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"/>

第二种方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?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的文件例如:

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

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

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

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

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

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android中,可以通过监听状态栏通知来获取通知的相关信息。在实现这个功能时,需要创建一个继承自NotificationListenerService的类,并重写onNotificationPosted和onNotificationRemoved方法。其中,onNotificationPosted方法用于在通知被发布时触发,而onNotificationRemoved方法用于在通知被移除时触发。 在具体的实现中,可以通过StatusBarNotification对象来获取通知的详细信息,例如通过sbn.getNotification()可以获取通知的内容。 为了使应用具备监听状态栏通知的功能,还需要在AndroidManifest.xml文件中进行相应的配置。需要在<manifest>标签内添加一个<service>标签,并设置android:name为你创建的NotificationListenerService的类名。同时,需要添加一个<intent-filter>标签,并设置action为"android.service.notification.NotificationListenerService"。最后,还需要添加android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"以获取相应的权限。 通过以上的步骤,你就可以在Android上监听状态栏通知并获取相应的信息了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [android监听Notification](https://blog.csdn.net/zhaicaixiansheng/article/details/47279251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Android 4.4 KitKat NotificationManagerService使用详解与原理分析(一)__使用详解](https://blog.csdn.net/yihongyuelan/article/details/40977323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值