问题:页面全屏显示,隐藏系统通知栏的两种不同写法的区别。
方法一:在AndroidManifest.xml文件中修改activity的theme为android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”
如下所示:
<?xml version="1.0" encoding="utf-8"?> <manifest package="testdemo.myapplication" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
这种写法页面可以达到全屏的效果,但是在布局中的控件的排列方式是垂直排列的情况下,控件之间上下的距离会比非全屏前大。
方法二:在setContentView方法前执行如下代码
如下所示:
@Override 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_main); }
这种写法也可以达到全屏的效果,而且对于布局中存在垂直排列方式的控件之间的垂直距离没有任何变化。
所以推荐第二种写法。