在设置内容之前,尝试在您的活动中使用此代码
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
隐藏Android 4.0及以下版本的状态栏
By setting the theme of application in manifest.xml file.
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
OR
By writing JAVA code in activity's onCreate() method.
@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中,代码解决方案对我无效。
<style name="ExampleTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item> <!-- add this line -->
</style>