魔幻厨房下载,未来的学校作文,战神王爷萌虎妃
本文包含3种隐藏顶部状态栏及标题栏和一种隐藏android 4.0平板底部状态栏的方法,分享给大家供大家参考,具体内容如下
方法一
public class mainactivity extends activity { @override protected 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.activity_main); } }
方法二
<!-- 同时隐藏状态栏和标题栏 --> <activity android:name="com.ysj.demo.mainactivity" 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 theme. --> <style name="apptheme" parent="appbasetheme"> <!-- all customizations that are not specific to a particular api-level can go here. --> <!-- 隐藏状态栏 --> <item name="android:windowfullscreen">true</item> <!-- 隐藏标题栏 --> <item name="android:windownotitle">true</item> </style>
注:
1、方法一中的两段代码要在setcontentview()之前。
2、方法二只能同时隐藏状态栏和标题栏。
3、方法一和方法二都只应用于单个activity。方法三应用于整个程序。
对于运行android 4.0以上系统的平板电脑,以上三种方法都不会隐藏屏幕下方的状态栏,须做如下处理。
public class startupactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_startup); /* * 隐藏运行android 4.0以上系统的平板的屏幕下方的状态栏 */ try { string procid = "79"; if (android.os.build.version.sdk_int >= android.os.build.version_codes.ice_cream_sandwich) procid = "42"; // ics // 需要root 权限 process proc = runtime.getruntime().exec(new string[] { "su", "-c", "service call activity " + procid + " s16 com.android.systemui" }); // was proc.waitfor(); } catch (exception ex) { toast.maketext(getapplicationcontext(), ex.getmessage(), toast.length_long).show(); } } @override protected void ondestroy() { // todo auto-generated method stub /* * 恢复运行android 4.0以上系统的平板的屏幕下方的状态栏 */ try { process proc = runtime.getruntime().exec(new string[] { "am", "startservice", "-n", "com.android.systemui/.systemuiservice" }); proc.waitfor(); } catch (exception e) { e.printstacktrace(); } super.ondestroy(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate the menu; this adds items to the action bar if it is present. getmenuinflater().inflate(r.menu.startup, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // todo auto-generated method stub switch (item.getitemid()) { case r.id.action_exit: finish(); break; } return true; } }
由于没有了状态栏,须在程序中提供退出程序的方法。
希望本文所述对大家学习android软件编程有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论