Android沉浸式顶部实现代码及效果
作者:手撕高达的村长 发布时间:2021-06-19 18:51:49
标签:Android,沉浸,顶部
研究了下这个,记录下代码。
主页面代码:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="Hello World!"
android:gravity="center"
android:background="@color/colorAccent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- android:fitsSystemWindows="true" android:clipToPadding="true"-->
</android.support.constraint.ConstraintLayout>
添加三个文件:三份 style 文件,即默认的values(不设置状态栏透明)、values-v19、values-v21(解决半透明遮罩问题)。
values 下 style.xml
<style name="TranslucentTheme" parent="AppTheme">
<!--在Android 4.4之前的版本上运行,直接跟随系统主题-->
</style>
values-v19 下 style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
values-v21 下 style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
这里需要在:AndroidMainfest.xml 里添加样式。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="controller.hzl.com.dingbu2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/TranslucentTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
主Acitivity没有修改。
效果图:
来源:https://www.cnblogs.com/sunxun/p/9543211.html


猜你喜欢
- 本文实例分析了C#中结构(struct)的部分初始化和完全初始化,分享给大家供大家参考。具体分析如下:假设有这样一个值类型struct,如下
- 一、直接插入排序基本思想:将一个记录插入到已排序的有序表中,使插入后的表仍然有序对初始关键字{49 38 65 97 76 13 27 49
- 在一些耗时的操作过程中,在长时间运行时可能会导致用户界面 (UI) 处于停止响应状态,用户在这操作期间无法进行其他的操作,为了不使UI层处于
- 说起异步,Thread,Task,async/await,IAsyncResult 这些东西肯定是绕不开的,今天就来依次聊聊他们1.线程(T
- 本文为大家分享了android倒计时控件,供大家参考,具体代码如下/* * Copyright (C) 2012 The * Project
- 目标依赖<!-- poi工具类--> <dependency>
- Java接口(interface)的概念及使用在抽象类中,可以包含一个或多个抽象方法;但在接口(interface)中,所有的方法必须都是抽
- 这里以list为介绍:private static readonly T[] s_emptyArray = new T[0];public
- LRU:Least Recently Used最近最少使用,当缓存容量不足时,先淘汰最近最少使用的数据。就像JVM垃圾回收一样,希望将存活的
- 员工管理系统1、准备工作资料下载内含源码 + 笔记 + web素材源码下载地址:http://xiazai.jb51.net/202105/
- Spring概述Spring就是为解决企业应用开发的复杂性而创建的,做为开源中间件,它使用基本的JavaBean来完成以前只可能有EJB(J
- 本文以C#代码为例介绍如何实现将彩色PDF文件转为灰度(黑白)的PDF文件,即 将PDF文档里面的彩色图片或者文字等通过调用PdfGrayC
- 现在一些app通常会在头部放一个广告位,底部放置一行小圆圈指示器,指示广告位当前的页码,轮播展示一些图片,这些图片来自于网络。这个广告位ba
- 本文实例为大家分享了java二叉查找树的具体代码,供大家参考,具体内容如下package 查找;import edu.princeton.c
- 本文介绍Android九宫格程序的设计代码,供大家参考,具体内容如下一.相关介绍(一)效果显示1.程序刚运行时的效果:2.在页面上点击选择并
- Android 3.0引入了CursorLoader实现异步加载数据,为了避免同步查询数据库时阻塞UI线程的问题。在API 11之前可以通过
- Jedis简介实际开发中,我们需要用Redis的连接工具连接Redis然后操作Redis,对于主流语言,Redis都提供了对应的客户端;提供
- 每次写批量的时候,都要在网上搜索一下,虽然都做过多次了,但具体的自己还是记不住(汗颜),所以索性今天就记录下来。前期说明:foreach的主
- 创建hander文件夹在 java 源码目录下创建hander文件夹, 在该文件夹下创建CustomAuthenticationFailHa
- 重写java object类的equals方法覆盖equals方法请遵守约定什么情况下要覆盖equals方法容易违反的对称性不易察觉的传递性