3種Android隱藏頂部狀態(tài)欄及標題欄的方法
本文包含3種隱藏頂部狀態(tài)欄及標題欄和一種隱藏Android 4.0平板底部狀態(tài)欄的方法,分享給大家供大家參考,具體內容如下
方法一
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隱藏標題欄 requestWindowFeature(Window.FEATURE_NO_TITLE); // 隱藏狀態(tài)欄 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); } }
方法二
<!-- 同時隱藏狀態(tài)欄和標題欄 --> <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. --> <!-- 隱藏狀態(tài)欄 --> <item name="android:windowFullscreen">true</item> <!-- 隱藏標題欄 --> <item name="android:windowNoTitle">true</item> </style>
注:
1、方法一中的兩段代碼要在setContentView()之前。
2、方法二只能同時隱藏狀態(tài)欄和標題欄。
3、方法一和方法二都只應用于單個Activity。方法三應用于整個程序。
對于運行Android 4.0以上系統(tǒng)的平板電腦,以上三種方法都不會隱藏屏幕下方的狀態(tài)欄,須做如下處理。
public class StartupActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_startup); /* * 隱藏運行Android 4.0以上系統(tǒng)的平板的屏幕下方的狀態(tài)欄 */ 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以上系統(tǒng)的平板的屏幕下方的狀態(tài)欄 */ 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; } }
由于沒有了狀態(tài)欄,須在程序中提供退出程序的方法。
希望本文所述對大家學習Android軟件編程有所幫助。
- Android中自定義標題欄樣式的兩種方法
- Android自定義狀態(tài)欄顏色與應用標題欄顏色一致
- Android 頂部標題欄隨滑動時的漸變隱藏和漸變顯示效果
- Android中去掉標題欄的幾種方法(三種)
- Android 全屏無標題欄的三種實現(xiàn)方法
- Android中隱藏標題欄和狀態(tài)欄的方法
- Android 使用CoordinatorLayout實現(xiàn)滾動標題欄效果的實例
- Android ScrollView滑動實現(xiàn)仿QQ空間標題欄漸變
- Android中隱藏狀態(tài)欄和標題欄的方法匯總(隱藏狀態(tài)欄、標題欄的五種方法)
- Android實現(xiàn)可折疊式標題欄
相關文章
Android實戰(zhàn)RecyclerView頭部尾部添加方法示例
本篇文章主要介紹了Android實戰(zhàn)RecyclerView頭部尾部添加方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11Android 中動態(tài)加載.jar的實現(xiàn)步驟
本文介紹動態(tài)加載 .jar的實現(xiàn)步驟,這將對你的android開發(fā)很有幫助,剛興趣的朋友可以了解下哦2013-01-01詳解Android平臺JSON預覽(JSON-handle)
這篇文章主要介紹了Android平臺JSON預覽(JSON-handle),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09Android實現(xiàn)動態(tài)切換組件背景的方法
這篇文章主要介紹了Android實現(xiàn)動態(tài)切換組件背景的方法,需要的朋友可以參考下2014-07-07