Android 15自定义设置导航栏与状态栏,EdgeToEdge适配

embedded/2024/10/22 16:28:45/

背景:android api 35,activity设置EdgeToEdge.enable((ComponentActivity) this)前提下
一、设置导航栏与状态栏颜色
设置的状态栏颜色,只需要设置fitsSystemWindows跟setOnApplyWindowInsetsListener
xml设置:
在这里插入图片描述
代码:

		getWindow().setNavigationBarContrastEnforced(false);ViewCompat.setOnApplyWindowInsetsListener(mMyGameRecycler, (v, windowInsets) -> {Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(insets.left, v.getPaddingTop(), insets.right, insets.bottom);return WindowInsetsCompat.CONSUMED;});
ViewCompat.setOnApplyWindowInsetsListener(mMyGameRecycler, (v, windowInsets) -> {Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(insets.left, v.getPaddingTop(), insets.right, insets.bottom);return WindowInsetsCompat.CONSUMED;});

二,设置导航栏自定义颜色半透明
布局activity_my_game.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/white"android:orientation="vertical"><Viewandroid:id="@+id/view_tool"android:layout_width="match_parent"android:layout_height="30dp"android:background="@color/white" /><include layout="@layout/toolbar_custom" /><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/swipe_target"android:layout_width="match_parent"android:layout_height="match_parent"android:overScrollMode="never" /><com.zhiyicx.baseproject.widget.EmptyViewandroid:id="@+id/empty_view"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>
</LinearLayout>

代码层面:

		//设置导航栏与状态栏图标颜色StatusBarUtils.setStatusBarLightMode(this.getWindow(), true);StatusBarUtils.setNavigationBarLightMode(this.getWindow(), true);//设置导航栏背景颜色与透明度,注意:如果布局fitsSystemWindows 为true时则不生效int bgcolor = Color.argb(0xe6, 0xFF, 0xFF,  0xFF);getWindow().setNavigationBarColor(bgcolor);//设置列表布局滑动时在导航栏背后,滑动到底时在导航栏顶部mMyGameRecycler.setClipToPadding(false);ViewCompat.setOnApplyWindowInsetsListener(mMyGameRecycler, (v, windowInsets) -> {Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(insets.left, v.getPaddingTop(), insets.right, insets.bottom);return WindowInsetsCompat.CONSUMED;});

注意:

  • 设置导航栏颜色时需要添加getWindow().setNavigationBarContrastEnforced(false),但是设置半透明时需要移除该行代码
  • 当设置fitsSystemWindows 时setNavigationBarColor会不生效

http://www.ppmy.cn/embedded/129599.html

相关文章

git工作笔记--git命令一把梭

环境&#xff1a;毕业的时候比较害怕git的这个工具的&#xff0c;工作多年以后&#xff0c;写一篇git常用提交代码的流程&#xff0c;只要使用常用的几个命令就可以实现代码提交&#xff0c;方便刚入门的小伙伴学习、使用。 安装git-bash 环境&#xff0c;注册码云&#xff0c…

OceanBase 2024 年度发布会|收好这份参会指南

2024 OceanBase 年度发布会 即将在 10月23日在北京举办 请查收为您准备的参会指南​​​​​ 交通指引 自驾 : 请导航定位至【北京望京凯悦酒店】地下车库&#xff0c;停车券请在离场前至签到处领取地铁: 14号线【阜通站】&#xff0c;C东南口出&#xff0c;步行410m 即可到达…

MatrixOne助力江铜集团打造炉前智慧作业AIoT大数据系统

客户简介 江西铜业集团有限公司是世界500强企业&#xff0c;同时也是中国最大的铜生产商之一&#xff0c;成立于1979年&#xff0c;总部位于江西省南昌市。 公司专注于铜及其相关产品的开采、冶炼和加工&#xff0c;业务覆盖矿产资源开发、冶炼加工、产品制造和国际贸易等领域…

【Vue进阶】第一章——熟悉Vue常用指令:从文本插值到表单绑定

目录 内容主要包含 1.Vue 常用指令介绍 目标 内容讲解 内容小结 2.文本插值v-html 目标 内容讲解 内容小结 3.绑定属性 v-bind:属性名或者 :属性名 (重点) 目标 内容讲解 内容小结 4.条件渲染v-if 目标 内容讲解 内容小结 5.条件渲染v-show 目标 内容讲解…

R实验——logistic回归、LDA、QDAKNN

数据集介绍&#xff1a; mpg&#xff0c;miles per gallon即油耗&#xff0c;这个数据集来自卡内基梅隆大学维护的StatLib库。1983年美国统计协会博览会使用了该数据集。这个数据集是对StatLib库中提供的数据集稍加修改的版本。根据Ross Quinlan(1993)在预测属性“mpg”中的使…

图片翻译软件有哪些?好用的在线图片翻译工具大盘点

最近国内外的活动好多好热闹&#xff0c;难道是接近年关了所以活动多了许多&#xff1f; 小编闲暇时还真去翻一翻国外有什么活动&#xff0c;结果发现海报上的花体英语好难看懂...... 所以就在网上直接搜图片翻译软件哪个好用&#xff1f;求助了广大才华横溢的网友&#xff0…

vector和list

vector 1.vector的介绍 https://legacy.cplusplus.com/reference/vector/vector/?kwvector 点击上面链接&#xff0c;进去搜索vector&#xff0c;就会有相应的文档介绍了。 使用STL的三个境界&#xff1a;能用&#xff0c;明理&#xff0c;能扩展&#xff0c;那么学习vect…

CST软件超表面--- 偏振片- 线圆极化转换,Floquet端口,S参数算轴比AR

这期我们看一个超表面极化分析&#xff0c;用到Floquet端口模数&#xff0c;S参数读出极化和轴比&#xff0c;还有平面波散射截面等技巧。 使用模板&#xff0c;频率0-25GHz&#xff0c;电场监视器8.06GHz: 画一片PEC&#xff1a; 画第二片PEC&#xff0c;insert到第一片里面&…