欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

3種Android隱藏頂部狀態(tài)欄及標(biāo)題欄的方法

 更新時(shí)間:2016年02月22日 10:51:33   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了3種Android隱藏頂部狀態(tài)欄及標(biāo)題欄的方法,還涉及一種隱藏Android 4.0平板底部狀態(tài)欄的方法,感興趣的小伙伴們可以參考一下

本文包含3種隱藏頂部狀態(tài)欄及標(biāo)題欄和一種隱藏Android 4.0平板底部狀態(tài)欄的方法,分享給大家供大家參考,具體內(nèi)容如下

方法一

public class MainActivity extends Activity
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);

 // 隱藏標(biāo)題欄
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 // 隱藏狀態(tài)欄
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  WindowManager.LayoutParams.FLAG_FULLSCREEN);

 setContentView(R.layout.activity_main);
 }

}

方法二

<!-- 同時(shí)隱藏狀態(tài)欄和標(biāo)題欄 -->
<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>
  <!-- 隱藏標(biāo)題欄 -->
  <item name="android:windowNoTitle">true</item>
</style>

注:

1、方法一中的兩段代碼要在setContentView()之前。

2、方法二只能同時(shí)隱藏狀態(tài)欄和標(biāo)題欄。

3、方法一和方法二都只應(yīng)用于單個(gè)Activity。方法三應(yīng)用于整個(gè)程序。

對(duì)于運(yùn)行Android 4.0以上系統(tǒng)的平板電腦,以上三種方法都不會(huì)隱藏屏幕下方的狀態(tài)欄,須做如下處理。

public class StartupActivity extends Activity
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_startup);
 
 /*
  * 隱藏運(yùn)行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 權(quán)限 
     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
 /*
  * 恢復(fù)運(yùn)行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)欄,須在程序中提供退出程序的方法。

希望本文所述對(duì)大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

最新評(píng)論