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

主页面代码: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. iOS 特定时间内才做某件事,有类似奇葩需求可以参考

    我们项目启动的时候要弹出一个广告窗口,很简单的一个功能,服务器的判断一下满足条件,即返回数据,客户端判断数据部位NULL,则弹出弹窗但是老板说,这个要时间短弹出,每天的中午12点到下午2点不能弹出来这 ...

  2. numpy.linspace()等差数列函数

    在numpy中的linspace()函数类似与arange().range()函数: arange() .range() 可以通过指定开始值.终值和步长创建一维等差数组,但其数组中不包含终值 通过   ...

  3. Python读文本文件

    file_object = open('thefile.txt') try: all_the_text = file_object.read() finally: file_object.close( ...

  4. Kafka不只是个消息系统

    作者丨 Jay Kreps Confluent 联合创始人兼 CEO Jay Kreps 发表了一篇博文,给出了 Kafka 的真正定位——它不只是个消息系统,它还是个存储系统,而它的终极目标是要让流 ...

  5. VC++对话框中加状态栏

    原文链接: http://blog.chinaunix.net/uid-9847882-id-1996528.html 方法一:1.添加成员变量CStatusBarCtrl m_StatusBar;2 ...

  6. ARGB和PARGB

    原文链接: http://blog.csdn.net/lnwaycool/article/details/8610313 ARGB和PARGB是针对32位图像而言的,Windows下图像可以是1位.4 ...

  7. window.location.href 与 window.loaction.replace区别

    window.location.href和window.location.replace的区别 1.window.location.href=“url”:改变url地址: 2.window.locat ...

  8. Android入门-新手如何成功创建一个Android小应用

    原文:http://android.eoe.cn/topic/summary 第一课程:Building Your First App [本课内容简介]欢迎加入到安卓应用的开发大潮中!这门课程会教授你 ...

  9. Python 构建方便的函数调用

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-14 @author: guaguastd @name: c ...

  10. mysql trigger 触发器

    创建触发器: CREATE [DEFINER = {user|CURRENT_USER}] TRIGGER trigger_name trigger_time trigger_event ON tbl ...