研究了下这个,记录下代码。

主页面代码: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 沉浸式顶部的更多相关文章

  1. Android沉浸式(侵入式)标题栏(状态栏)Status(一)

     Android沉浸式(侵入式)标题栏(状态栏)Status(一) 现在越来越多的APP设计采用这种称之为沉浸式状态栏(Status)的设计,这种沉浸式状态栏又称之"侵入式"状 ...

  2. android 沉浸式状态栏的实现

    本文介绍一种简单的实现沉浸式状态栏的方法,要高于或等于api19才可以. 实现android沉浸式状态栏很简单,添加代码两步就可以搞定. 一.在activity中添加 getWindow().addF ...

  3. Android沉浸式状态栏(透明状态栏)最佳实现

    Android沉浸式状态栏(透明状态栏)最佳实现 在Android4.4之前,我们的应用没法改变手机的状态栏颜色,当我们打开应用时,会出现上图中左侧的画面,在屏幕的顶部有一条黑色的状态栏,和应用的风格 ...

  4. Android 沉浸式状态栏 实现方式二 ( 更简单 )

    以前写过一个沉浸式状态栏 的实现方式 Android 沉浸式状态栏 实现方式一 现在有个更为简单的实现方式 . 相关链接 http://www.apkbus.com/forum.php?mod=vie ...

  5. Android沉浸式(侵入式)标题栏(状态栏)Status(三)

     Android沉浸式(侵入式)标题栏(状态栏)Status(三) 从附录文章1,2可以看到,依靠Android系统提供的标准方案,状态栏即便在透明状态下,仍然有些半透明而不是全透明.本文是And ...

  6. Android沉浸式(侵入式)标题栏(状态栏)Status(二)

     Android沉浸式(侵入式)标题栏(状态栏)Status(二) 附录1以xml写style实现了Android沉浸式(侵入式)状态栏(标题栏),同样以上层Java代码实现.在附录文章1的基础上 ...

  7. [置顶] Xamarin android沉浸式状态栏

    虽然关于android "沉浸式"状态栏有很多博客介绍过,从小菜到大神无一例外.我第一次看到这种"沉浸"式的效果我也以为真的是这么叫,然而根本不是这么回事,完全 ...

  8. Android 沉浸式状态栏完美解决方案

    现在搜索Android 沉浸式状态栏,真的是一堆一堆,写的特别多,但是真正用的舒服的真没有,在这里自己整理一下开发记录 注意,在使用这个步骤过程之前,请把之前设置的代码注释一下 把布局带有androi ...

  9. flutter android沉浸式状态栏

    import 'package:flutter/services.dart'; import 'dart:io'; class _MyAppState extends State<MyApp&g ...

随机推荐

  1. TensorFlow实战

    TensorFlow实战:Chapter-1(TensorFlow介绍) TensorFlow实战:Chapter-2(TensorFlow入门) TensorFlow实战:Chapter-3(CNN ...

  2. mongodb常用命令小结

    一.基于条件的查询 db.getCollection('monitor_log') .find({"requestUrl" : /app\/v1\/findcards\/cn/, ...

  3. 【转】Braid - 一个发人深思的游戏

    Braid - 一个发人深思的游戏 我已经很久很久没有打游戏了(如果不算 Angry Birds 之类用来打发时间的游戏的话).我的最后一个真正意义上的游戏机,是 PlayStation 1.在那上面 ...

  4. asp.net url址址中中文汉字参数传递乱码解决方法

    中文乱码是网站开发中会常碰到的问题,今天我们来讲一下关于url址址中中文汉字参数传递乱码解决方法,有需要的朋友可以参考下.在cs文件里传参的时候用UrlEncode: Response.Redirec ...

  5. php分享二十二:设计模式

    策略模式与观察者模式的区别: 策略是我现在方法有几个东西 我传入不同的参数就能拿到不同的东西,就像是spring中的populate,我传入不同的handler对象进来 返回的可以是javaBean或 ...

  6. 两table水平滚动条级联滚动(同步滚动)。 table1放标题,table2放内容。

    //table1=head和table2=body水平滚动条级联滚动 $(document).ready(function () { $("#bodyPanel").scroll( ...

  7. Java常考面试题(五)

    序言 好好努力. ---WH 一.Iterator和ListIterator的区别是什么? 自我解答: Iterator是针对所有collection来使用的,而看名字ListIterator,顾名思 ...

  8. python常用运维脚本实例

    转载  file是一个类,使用file('file_name', 'r+')这种方式打开文件,返回一个file对象,以写模式打开文件不存在则会被创建.但是更推荐使用内置函数open()来打开一个文件 ...

  9. 常用sql自定义函数

    --把数字转为千分位格式的字符串显示,调用如 select dbo.f_splitstr(11111111111111) CREATE FUNCTION [dbo].[f_splitstr]( @st ...

  10. Socket网络编程--Libev库学习(3)

    这一小节继续讲解各个观察器(Watcher). 上一小节已经讲解了ev_io(IO可读可写观察器),ev_stat(文件属性变化观察器),ev_signal(信号处理观察器),ev_timer(定时器 ...