android 沉浸式状态栏 与应用统一颜色样式
public void setTransparentStatusBar() {
View decorView = getWindow().getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;//表示让应用主题内容占据系统状态栏的空间
decorView.setSystemUiVisibility(option);
setStatusBarColor(Color.TRANSPARENT);//设置状态栏颜色为透明
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//android6.0以后可以对状态栏文字颜色和图标进行修改
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
public void setStatusBarColor(int color) {
Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(color);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.lzyzsd.jsbridge.BridgeWebView
android:fitsSystemWindows="true"
android:clipToPadding="true"
android:id="@+id/main_wv"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</com.github.lzyzsd.jsbridge.BridgeWebView>
android:fitsSystemWindows="true"
android:clipToPadding="true"
加入到顶部布局控件中去,注意不是根布局,这样就可以自适应了。