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没有修改。
效果图:
Android 沉浸式顶部的更多相关文章
- Android沉浸式(侵入式)标题栏(状态栏)Status(一)
Android沉浸式(侵入式)标题栏(状态栏)Status(一) 现在越来越多的APP设计采用这种称之为沉浸式状态栏(Status)的设计,这种沉浸式状态栏又称之"侵入式"状 ...
- android 沉浸式状态栏的实现
本文介绍一种简单的实现沉浸式状态栏的方法,要高于或等于api19才可以. 实现android沉浸式状态栏很简单,添加代码两步就可以搞定. 一.在activity中添加 getWindow().addF ...
- Android沉浸式状态栏(透明状态栏)最佳实现
Android沉浸式状态栏(透明状态栏)最佳实现 在Android4.4之前,我们的应用没法改变手机的状态栏颜色,当我们打开应用时,会出现上图中左侧的画面,在屏幕的顶部有一条黑色的状态栏,和应用的风格 ...
- Android 沉浸式状态栏 实现方式二 ( 更简单 )
以前写过一个沉浸式状态栏 的实现方式 Android 沉浸式状态栏 实现方式一 现在有个更为简单的实现方式 . 相关链接 http://www.apkbus.com/forum.php?mod=vie ...
- Android沉浸式(侵入式)标题栏(状态栏)Status(三)
Android沉浸式(侵入式)标题栏(状态栏)Status(三) 从附录文章1,2可以看到,依靠Android系统提供的标准方案,状态栏即便在透明状态下,仍然有些半透明而不是全透明.本文是And ...
- Android沉浸式(侵入式)标题栏(状态栏)Status(二)
Android沉浸式(侵入式)标题栏(状态栏)Status(二) 附录1以xml写style实现了Android沉浸式(侵入式)状态栏(标题栏),同样以上层Java代码实现.在附录文章1的基础上 ...
- [置顶]
Xamarin android沉浸式状态栏
虽然关于android "沉浸式"状态栏有很多博客介绍过,从小菜到大神无一例外.我第一次看到这种"沉浸"式的效果我也以为真的是这么叫,然而根本不是这么回事,完全 ...
- Android 沉浸式状态栏完美解决方案
现在搜索Android 沉浸式状态栏,真的是一堆一堆,写的特别多,但是真正用的舒服的真没有,在这里自己整理一下开发记录 注意,在使用这个步骤过程之前,请把之前设置的代码注释一下 把布局带有androi ...
- flutter android沉浸式状态栏
import 'package:flutter/services.dart'; import 'dart:io'; class _MyAppState extends State<MyApp&g ...
随机推荐
- OpenCV 学习笔记 01 安装OpenCV及相关依赖库
本次学习是基于Window10进行的.语言为python3. 1 与opencv相关的库简介 1.1 numpy numpy 是 OpenCV 绑定 python 时所依赖的库,此意味着numpy在安 ...
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
iphone 开发中使用zbar时遇到的几个典型问题解决方法. 在近期的一个ios项目中使用到了一个二维码扫描库(Qrcode)--ZBar, 期间遇到2个问题. 1. zbar下载后使用其l ...
- Java原理之HashMap
一下JDK1.7测试没问题,1.8就不一样了,应该散列的更优化. 最近看了很多java底层之HashMap的原理,根据自己的实现如下: package com.gmq.chapter02; impor ...
- html5 audio组件禁止下载
参考链接:https://wdd.js.org/audio-hide-download-icon.html 1. controlsList=”nodownload”// 这个方法只支持 Chrome ...
- C# 获取接口数据(xml格式)转为json格式
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- Android下的联网下载的操作
一:从网络下载图片 MainActivity: NetService 1.由路径获取Url 2.使用url打开HttpURLConnection连接 3.根据路径查找本地sd卡是否有缓存文件,如果文件 ...
- php分享十六:php读取大文件总结
一:file函数读取 file()函数的效率很底下 如果是有规律的文件.比如每行一条相应数据.那么尽量不要是用file()函数,可以使用file_get_contents()然后用explode切割. ...
- springBoot bean注入
1.@Component:把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/> 2.@Autow ...
- Android 常用算法
排序算法 简单排序算法 冒泡排序 两两比较相邻记录的关键字,如果反序则交换,直到没有反序的记录为止 直接插入排序 通过 n-i 次关键字间的比较,从 n-i+1 个记录中选出关键字最小的记录,并和第 ...
- 一个C#操作Excel类,功能比较全
using System; using System.Data; using System.Configuration; using System.Web; using Microsoft.Offic ...