日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 隐藏状态栏,沉浸式状态栏,状态栏背景色,状态栏字体色,透明状态工具类

發布時間:2023/12/10 Android 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 隐藏状态栏,沉浸式状态栏,状态栏背景色,状态栏字体色,透明状态工具类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

? ?

?

設置狀態欄顏色

if (Build.VERSION.SDK_INT>21){getWindow().setStatusBarColor(getResources().getColor(R.color.mainc)); }

方法2

<color name="colorPrimary">#3F51B5</color>

//取消標題

requestWindowFeature(Window.FEATURE_NO_TITLE);

//?隱藏狀態欄——全屏模式

1、方法1

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);?

?

2、方法2

if (Build.VERSION.SDK_INT >= 19) {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| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); }

?

設置狀態欄背景色,沉浸模式

?

if (Build.VERSION.SDK_INT >= 21) {View decorView = getWindow().getDecorView();int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;decorView.setSystemUiVisibility(option);getWindow().setNavigationBarColor(Color.TRANSPARENT);getWindow().setStatusBarColor(Color.TRANSPARENT); }


設置狀態欄字體色

getWindow().setNavigationBarColor(Color.TRANSPARENT);//底部軟鍵盤背景色getWindow().setStatusBarColor(Color.TRANSPARENT);//狀態欄背景色


????????getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_VISIBLE);//白色
// ???????getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//黑色
?

透明狀態工具類:

?

/*** @author : LGQ* @date : 2020/07/01 20* @desc :*/public class StatusDelegate {private final int mStatusHeight;private boolean mFitStatusBar;public StatusDelegate(Context context) {this(context, false);}public StatusDelegate(Context context, boolean fitStatusBar) {mStatusHeight = getStatusHeight(context);mFitStatusBar = fitStatusBar;}public int getStatusHeight() {return mStatusHeight;}/*** 是否適配狀態欄** @return*/public boolean isFitStatusBar() {return mFitStatusBar;}/*** 設置適配狀態欄** @param fitStatusBar*/public void setFitStatusBar(boolean fitStatusBar) {mFitStatusBar = fitStatusBar;}/*** 可以設置透明狀態欄** @return*/public boolean canTranslucentStatus() {return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;}/*** 是否應該去適配狀態欄** @return*/public boolean toFitStatusBar() {return isFitStatusBar() & canTranslucentStatus();}private int getStatusHeight(Context context) {int result = 0;try {Resources resources = context.getResources();int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");if (resourceId > 0) {int sizeOne = context.getResources().getDimensionPixelSize(resourceId);int sizeTwo = Resources.getSystem().getDimensionPixelSize(resourceId);if (sizeTwo >= sizeOne) {return sizeTwo;} else {float densityOne = context.getResources().getDisplayMetrics().density;float densityTwo = Resources.getSystem().getDisplayMetrics().density;float f = sizeOne * densityTwo / densityOne;return (int) ((f >= 0) ? (f + 0.5f) : (f - 0.5f));}}} catch (Resources.NotFoundException ignored) {return 0;}return result;} }

?

public class StatusBarView extends View {private static int mStatusBarHeight;private StatusDelegate mStatusDelegate;public StatusBarView(Context context) {this(context, null);}public StatusBarView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);mStatusDelegate = new StatusDelegate(context);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int newHeightSpec;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {newHeightSpec = MeasureSpec.makeMeasureSpec(mStatusDelegate.getStatusHeight(), MeasureSpec.EXACTLY);} else {newHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);}super.onMeasure(widthMeasureSpec, newHeightSpec);} }

引用

<cn.dlc.dalianmaomeikuang.utils.StatusBarViewandroid:id="@+id/topli"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/transparent"></cn.dlc.dalianmaomeikuang.utils.StatusBarView>

總結

以上是生活随笔為你收集整理的Android 隐藏状态栏,沉浸式状态栏,状态栏背景色,状态栏字体色,透明状态工具类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。