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);

    }

    @Override
    protected 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.StatusBarView
    android:id="@+id/topli"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent"></cn.dlc.dalianmaomeikuang.utils.StatusBarView>
       ViewCompat.setOnApplyWindowInsetsListener(allli, new OnApplyWindowInsetsListener() {
            public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                Insets systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                v.setPadding(         0,
                        0,
//                max(windowInsets.displayCutout?.safeInsetTop ?: 0, systemInsets.top),
                        0,
                        systemInsets.bottom);

                return insets.consumeSystemWindowInsets();
            }
        });
        WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

   private fun openFitsWindow(){
        if(isNeedPadding){
            ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
                //防止UI冲突
                val systemInsets =
                    windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
                view.updatePadding(
                    binding.root.paddingLeft,
                    systemInsets.top,
//                max(windowInsets.displayCutout?.safeInsetTop ?: 0, systemInsets.top),
                    binding.root.paddingRight,
                    systemInsets.bottom
                )
                WindowInsetsCompat.CONSUMED
            }
            WindowCompat.setDecorFitsSystemWindows(window, false)
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 随着移动设备的普及,越来越多的人开始使用android系统的手机或平板电脑。然而,很多人对于android系统自带的状态栏布局并不满意,这时候我们就需要一款android状态栏沉浸软件来改善这种情况。 简单来讲,android状态栏沉浸软件可以让用户将原本系统自带的状态栏隐藏起来,使屏幕更加纯净简洁。同时,用户可以根据自己的喜好自定义状态栏的背景颜透明度、图标等一系列属性。这种软件能够让用户在使用手机或平板电脑时拥有更好的使用体验,同时提高了屏幕的利用率。 值得一提的是,android状态栏沉浸软件在不同的手机品牌和系统版本下可能会存在兼容性问题,所以在选择使用前最好先查询一下相关的使用教程和注意事项。 总之,android状态栏沉浸软件是一款非常实用的软件,可以提升用户的使用体验和工作效率,如果你想要获得更好的屏幕展示效果,那么不妨尝试一下这种软件。 ### 回答2: Android 状态栏沉浸软件是一种让用户可以自定义和优化 Android 系统状态栏显示方的工具。在大多数 Android 设备上,状态栏是一个固定的元素,通常显示设备的时间、电量、信号和通知等信息,占据屏幕的顶部。然而,有些用户希望将应用程序占用的可用空间最大化,因此状态栏可能会显得有些碍眼。同时,一些用户喜欢自定义外观,以便与自己设备的主题相匹配。 Android 状态栏沉浸软件通过隐藏或重定义状态栏,增加了屏幕的可用空间。例如,可以让状态栏完全消失,节省了顶部的宝贵空间。或者,也可以选择改变状态栏的颜以配合设备的主题,这样便于与屏幕的其他元素相协调。 除了可用屏幕空间和外观之外,状态栏沉浸软件还可以在阅读、视频观看或游戏等场景中提供更佳的用户体验。正如人们不喜欢在大屏幕电视上看影片时在底部或顶部看到那些控制按钮一样,手机屏幕也将会受到相同的影响。当状态栏隐藏后,用户可以获得更清晰的视觉体验。 总的来说,Android 状态栏沉浸软件为用户提供了更好的自定义体验,同时也更增加了屏幕显示效果。无论是为优化手机的可用空间,还是为了更好的视觉体验,它都是一种非常有用的工具。 ### 回答3: Android状态栏沉浸是一种让应用程序能够使用全屏显示的功能。传统的Android状态栏会出现在屏幕最上方,占用屏幕的一部分,导致应用程序无法使用整个屏幕。当一个应用程序启用状态栏沉浸时,系统的状态栏会被隐藏,使应用程序能够使用整个屏幕。 有很多现有的Android状态栏沉浸软件,让你能够启用这个功能,例如SystemUI Tuner、SetEdit等。这些软件有不同的设置选项,可以供用户选择。 对于程序员来说,他们也可以利用Android的API来实现沉浸。这需要他们在代码中添加一些指令,以告诉Android系统如何隐藏状态栏。不过这对一般用户来说,可能会比较困难。 总的来说,状态栏沉浸软件可以让用户在使用应用程序时,是能够看到更多的内容。这种功能通常更适合用于娱乐和游戏,而非日常使用。切记使用状态栏沉浸,需要注意不要被短信,来电等信息所打扰。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值