当前位置: 首页 > news >正文

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

背景: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.lryc.cn/news/470289.html

相关文章:

  • 设计模式概览
  • 力扣每日一题打卡 684. 冗余连接
  • 什么是微服务中的反应性扩展?
  • 【MyBatis】MyBatis-config标签详解
  • 使用AVPlayer进行音频播放开发基础设计
  • API网关的作用--为什么微服务需要一个API网关?
  • [0154].第5节:IDEA中创建Java Web工程
  • React03 组件 Props
  • 多线程——线程安全的集合类
  • 自动化数据库管理:如何通过存储过程动态创建 MySQL 对象
  • 480p 720p 1080p 2k 4k 8k 12k分辨率视频分别占用多大带宽?
  • unity中GameObject介绍
  • 洛谷——P8468 [Aya Round 1 C] 文文的构造游戏(01构造问题)
  • 双击热备和负载均衡的区别
  • 如何使用 cPanel 部署 WordPress临时网站
  • Android 自定义 Dialog 实现列表 单选,多选,搜索
  • 下载地址合辑(持续更新)
  • Android Kotlin 高阶函数详解及其在协程中的应用
  • CSS基础—网页布局(重点!)
  • 【Fargo】17:vs工程转qt构建:QT6 不支持32bit转向qt5.15.2
  • ​智能电表蓝牙芯片方案
  • miRNA分析流程学习(一)/TCGAmiRNA数据下载
  • 西南大学软件专硕考研难度分析!
  • 计算机前沿技术-人工智能算法-大语言模型-最新研究进展-2024-10-21
  • 安全芯片 OPTIGA TRUST M 使用介绍与示例(基于STM32裸机)
  • 【AI换装整合及教程】CatVTON:时尚与科技的完美融合
  • 接口测试(七)jmeter——参数化(RandomString函数)
  • simple_php
  • 网络搜索引擎Shodan(4)
  • 【Flask】一、安装与第一个测试程序