全屏
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set no title bar 需要在setContentView之前调用
requestWindowFeature(Window.FEATURE_NO_TITLE);
//如果上面的不起作用,可以换成下面的。
if (getSupportActionBar()!=null) getSupportActionBar().hide();
if (getActionBar()!=null) getActionBar().hide();
//no status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_camera_view);
initView();
}
沉浸式,TranslucentTheme
为页面指定主题样式
<activity
android:name="LoginActivity"
android:screenOrientation="portrait"
android:theme="@style/TranslucentTheme" />
style.xml
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
style.xml(v19)
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
style.xml(v21)
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>