国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2020-04-11 10:46:31
字體:
來源:轉載
供稿:網友

本文包含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軟件編程有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 锦屏县| 万盛区| 扶绥县| 台江县| 东兴市| 咸丰县| 浦东新区| 武乡县| 贵南县| 镇江市| 宜昌市| 周至县| 临武县| 呼玛县| 竹北市| 仪征市| 上饶县| 阿拉善右旗| 三河市| 洛浦县| 陆川县| 凤山市| 盐津县| 砀山县| 五指山市| 灌南县| 遵义县| 鱼台县| 法库县| 宿迁市| 龙南县| 洪江市| 甘洛县| 安塞县| 八宿县| 钟祥市| 噶尔县| 普安县| 山阳县| 洪雅县| 昌吉市|