Android全屏显示问题 去掉系统标题栏 去掉系统菜单栏相关记录

全屏显示在开发中常常会遇到,根据需求直接去掉标题栏即可。但今天在一个韩国客户那里发现很多机顶盒既然存在自带菜单栏的情况,看起来非常别扭,经过一番搜索后最后发现其实也不难,是你太悲观了。

去掉系统自动菜单栏

private void hideSystemUI() {
	    // Enables regular immersive mode.
	    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
	    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
	    View decorView = getWindow().getDecorView();
	    decorView.setSystemUiVisibility(
	            View.SYSTEM_UI_FLAG_IMMERSIVE
	            // Set the content to appear under the system bars so that the
	            // content doesn't resize when the system bars hide and show.
	            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
	            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
	            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
	            // Hide the nav bar and status bar
	            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
	            | View.SYSTEM_UI_FLAG_FULLSCREEN);
	}

显示系统菜单栏

// Shows the system bars by removing all the flags
	// except for the ones that make the content appear under the system bars.
	private void showSystemUI() {
	    View decorView = getWindow().getDecorView();
	    decorView.setSystemUiVisibility(
	            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
	            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
	            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
	}

一般通过监听onWindowFocusChanged的变化来进行隐藏和显示

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

去掉标题栏

第一种、在activity的setContentView()方法的前面设置

requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置无标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN); // 设置全屏

第二种、在AndroidManifest.xml下设置,需要全局设置的话就在application下,否则在对应的activity上设置即可

<android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
或者
android:theme="@style/Theme.AppCompat.NoActionBar

第三种、新建一个style.xml的文件、在对应的application/activity上调用 "android:theme="@style/youresourcesname""

<?xml version="1.0" encoding="UTF-8" ?>
 <resources>
 <style name="notitle">
     <item name="android:windowNoTitle">
         true
     </item>
 </style>
 </resources>

THE END 谢谢查看

编辑:吴明辉

没有更多推荐了,返回首页