【发布时间】:2016-02-15 19:13:00
【问题描述】:
【问题讨论】:
-
状态栏是我要删除的,而不是操作栏。
标签: android android-activity android-statusbar
【问题讨论】:
标签: android android-activity android-statusbar
在设置内容之前在你的活动中尝试这个
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
【讨论】:
在 Android 4.0 及更低版本上隐藏状态栏
通过在 manifest.xml 文件中设置应用程序的主题。
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
或
通过在 Activity 的 onCreate() 方法中编写 JAVA 代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
在 Android 4.1 及更高版本上隐藏状态栏
通过在 Activity 的 onCreate() 方法中编写 JAVA 代码。
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
【讨论】:
if (Build.VERSION.SDK_INT < 16)//before Jelly Bean Versions
{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else // Jelly Bean and up
{
View decorView = getWindow().getDecorView();
// Hide the status bar.
int ui = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(ui);
//Hide actionbar
ActionBar actionBar = getActionBar();
actionBar.hide();
}
【讨论】:
唯一有效的答案(至少对我来说)
在styles.xml中
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
</style>
</resources>
代码内解决方案在 4.4.2 Kitkat 中对我不起作用。
【讨论】:
打开 styles.xml 并更新您的活动使用的样式:
<style name="ExampleTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item> <!-- add this line -->
</style>
【讨论】: