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>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415915.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SVN错误信息汇总

Subversion 错误信息一览表 注意&#xff1a; 不同的客户端&#xff08;命令行&#xff0c;TortoiseSVN, AnkhSVN, Subclipse等&#xff09;的出错信息可能稍有不同。 下面表格中的出错信息以 http://svn.moon.ossxp.com/svn/test 版本库做示例&#xff0c;仅供参考。 编…

二项分布 , 多项分布, 以及与之对应的beta分布和狄利克雷分布

1. 二项分布与beta分布对应   2. 多项分布与狄利克雷分布对应 3. 二项分布是什么&#xff1f;n次bernuli试验服从 二项分布 二项分布是N次重复bernuli试验结果的分布。 bernuli实验是什么&#xff1f;做一次抛硬币实验&#xff0c;该试验结果只有2种情况&#xff0c;x 1, 表示…

mpvue 从零开始 女友的衣装 1 pages

pages文件夹就像一个大橱柜&#xff0c;里面放着各种精美的衣装&#xff0c;你也可以理解为供小程序的页面。 1、制造衣服 我在pages页面下新建了3个页面 market 广告市场task 任务中心my 个人中心 以market为例&#xff0c;写最简单的代码 <template><div class…

android 动态设置View的高度和宽度,ViewTreeObserver使用

private int mMonitorHeight 0; private int mMonitorWidth 0; private boolean bisSetScreen false; 动态设置满屏宽度 ViewTreeObserver vto2 monitor.getViewTreeObserver(); vto2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){Overridep…

Oracle RDA(Remote Diagnostic Agent) 工具说明

Oracle RDA(Remote Diagnostic Agent) 工具说明 分类&#xff1a; Oracle 性能调优 Oracle 高级知识 一.RDA 说明 RDA(RemoteDiagnostic Agent)是oracle用来收集、分析数据库的工具&#xff0c;运行该工具不会改变系统的任何参数&#xff0c;RDA收集的相关数据非常全面&…

替换元素节点replaceChild()

replaceChild 实现子节点(对象)的替换。返回被替换对象的引用。 语法&#xff1a; node.replaceChild (newnode,oldnew ) 参数&#xff1a; newnode : 必需&#xff0c;用于替换 oldnew 的对象。 oldnew : 必需&#xff0c;被 newnode 替换的对象。 注意: 1. 当 oldnode 被替…

mpvue 从零开始 女友的发带 2 window中设置

女友头上发带的颜色和文字是可以设置的&#xff0c;通过配置app.json中的window参数。 "window": {"backgroundTextStyle": "light","navigationBarBackgroundColor": "#58A94E","navigationBarTitleText": "…

mpvue 从零开始 女友使用 3 rpx 适应大小

对于各种机型屏幕尺寸的大小&#xff0c;小程序给出了解决方案&#xff0c;使用rpx。 微信小程序规定屏幕的宽度为750rpx。 无论是在iPhone6上面还是其他机型上面都是750rpx的屏幕宽度&#xff0c;拿iPhone6来讲&#xff0c;屏幕宽度为375px&#xff0c;把它分为750rpx后&#…

mysql中独立表空间与共享表空间之前如何切换

环境 mysql版本&#xff1a;5.7.19 官方文档&#xff1a;(https://dev.mysql.com/doc/refman/5.7/en/innodb-multiple-tablespaces.html) 查看目前属于哪种表空间 mysql> show variables like %per_%; 共享表空间会显示为off&#xff1a; 独立表空间会显示为on&#xff1a; …

常见Eclipse SVN插件报错解决方法

名师指导: 常见Eclipse SVN插件报错解决方法 在学习SVN的过程中&#xff0c;你经常会遇到SVN插件问题&#xff0c;本文介绍一下在安装SVN插件时常见Eclipse SVN插件报错信息问题&#xff0c;希望本文介绍对你的学习有所帮助。 AD&#xff1a; 本节和大家一起看一下SVN插件在安装…

android 标题栏颜色渐变和阴影,ScrollView上下滑动监听,及判断scrollView是否滚动到底部

1、创建 ScrollListener 接口监听滑动距离 public interface ScrollListener {void onScrollChanged(ScrollListenerView scrollView, int x, int y, int oldX, int oldY); }view阴影属性 android:elevation"4dp"2、重写 ScrollView 自定义 ScrollListenerView …

mpvue 从零开始 女友的来电 4 flyio

女友给我打电话&#xff0c;我的号码是fly.js&#xff0c;可以进行数据请求。 1、安装需要的库flyio、qs yarn add flyio qs2、src目录下新建api/index.js&#xff0c;填写下面代码 import Fly from flyio/dist/npm/wx; import qs from qs;const fly new Fly(); const host…

Linux下MySQL 安装配置

MySQL 是最流行的关系型数据库管理系统&#xff0c;由瑞典MySQL AB公司开发&#xff0c;目前属于Oracle公司。 MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。 MySQL由于其体积小、速度快、总体拥有成本低&#xff0c;尤其是开放源码这一特点&#xff0c;一般中小型…

向oracle表空间添加一个数据文件命令

向表空间添加一个数据文件SQL语句&#xff1a; ALTER TABLESPACE sde ADD DATAFILED:\app\Administrator\oradata\orcl\sde1 SIZE 400M; 记得加上自动扩展的命令&#xff1a;autoextend on

android 监听webView滑动距离和标题栏颜色渐变

重写webView之 X5WebView import android.annotation.SuppressLint; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.ActionMode; import android.view.Menu; …

mpvue 从零开始 女友拉黑了我 5 不在以下request 合法域名列表中,请参考文档

上一篇&#xff0c;才调通了接口&#xff0c;试了几次&#xff0c;都成功&#xff0c;突然&#xff0c;微信报错了。 VM6239:1 https://www.easy-mock.com 不在以下 request 合法域名列表中&#xff0c;请参考文档&#xff1a;https://mp.weixin.qq.com/debug/wxadoc/dev/api…