標籤:des android style http io os ar java for
http://www.xuebuyuan.com/558284.html
方法一
public class MainActivity extends Activity{@Overrideprotected 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{@Overrideprotected 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(); } }@Overrideprotected 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();}@Overridepublic 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;}@Overridepublic boolean onOptionsItemSelected(MenuItem item){// TODO Auto-generated method stubswitch (item.getItemId()){case R.id.action_exit:finish();break;}return true;}}
由於沒有了狀態列,須在程式中提供退出程式的方法。
Android全屏(包含3種隱藏頂部狀態列及標題列和一種隱藏Android 4.0平板底部狀態列的方法)