如何隐藏状态栏 android 4.1.2 ?我想要在 4.1.2 版本上隐藏状态栏的解决方案
我想在我的应用程序上隐藏状态栏
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
此代码不适用于版本 4.1.2
如何隐藏状态栏 android 4.1.2 ?我想要在 4.1.2 版本上隐藏状态栏的解决方案
我想在我的应用程序上隐藏状态栏
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
此代码不适用于版本 4.1.2
由于 Jellybean (4.1) 有一个不依赖于 WindowManager 的新方法。而是在 Window 之外使用 setSystemUiVisibility,与使用 WindowManager 标志相比,这可以让您对系统栏进行更精细的控制。这是一个完整的例子:
if (Build.VERSION.SDK_INT < 16) { //ye olde method
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else { // Jellybean and up, new hotness
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();
if(actionBar != null) {
actionBar.hide();
}
}
将此添加到您要隐藏状态栏的活动标记下的清单文件中
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
你完成了:)
在 oncreate() 方法中添加这些行
requestWindowFeature(Window.FEATURE_NO_TITLE);// hide statusbar of Android
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
希望这是您正在寻找的......在 setcontentview 之前添加:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
我认为这会奏效
public static void hideStatusBar(Activity activity) {
WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
activity.getWindow().setAttributes(attrs);
activity.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
public static void showStatusBar(Activity activity) {
WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
activity.getWindow().setAttributes(attrs);
activity.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
在您的 onCreate 方法中编写此代码
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
在这个onWindowFocusChanged()
方法中写一行
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
这对我有用:
protected 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_splash);
}