• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android通知栏沉浸式/透明化完整解决方案,root不完整解决方法

Android通知栏沉浸式/透明化完整解决方案,root不完整解决方法

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android 沉浸式通知栏,android 沉浸式状态栏,android状态栏沉浸,android 沉浸式标题栏,android 沉浸栏等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android通知栏沉浸式/透明化完整解决方案,root不完整解决方法


转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6640649.html 

 

参考文献:https://github.com/ljgsonx/adaptiveStatusBar

 

Google在Android 4.4版本加入了半透明的界面样式,在Android 5.0的时候推出了Material Design的概念。

这些样式的加入使得原本死板、丑陋、和App颜色不一致的通知栏变得更亲和、顺眼、用户体验更友好。

 

作者是常年做对日项目的,对日项目以界面简洁功能强大而著称。最近客户要求UI方面做一些改变,让App看上去给用户感觉更友好。所以就提到了Android 4.4以后的通知栏问题。

网上关于通知栏的文章铺天盖地,什么沉浸式,什么半透明。。。挺会拽词。也不乏有Android大神也写过类似的文章,但是那文章能看?长篇大论,程序员够累了,哪有那些时间看你在那里车轱辘话满天飞,说了一大顿表达不明白,浪费时间,写的一堆垃圾文章。

 

本篇文章杜绝冗余,做到最简单,最实用,对日项目比的不是代码量,而是最少的代码写出最漂亮的程序。

 

文章对应的项目已上传到Github,欢迎Star,欢迎Fork。地址:https://github.com/cnwutianhao/ImmersiveDemo

 

先上Gif图,Android 4.4 和 Android 6.0 实现样式效果之后的对比图

Android 4.4                                                                    Android 6.0

       

实现样式效果我们有两种方案

①DrawerLayout+Toolbar

②ActionBar

 

下面我们就来一一实现

①DrawerLayout+Toolbar

添加依赖库(谷歌提供)

compile 'com.android.support:design:25.3.1'

布局代码1:使用 DrawerLayout做最外层,引入NavigationView侧边抽屉控件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/id_drawerlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.tnnowu.android.demo17032801.MainActivity">

    <include layout="@layout/content_layout" />

    <android.support.design.widget.NavigationView
        android:id="@+id/id_navigationview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        app:itemTextColor="@color/c_light_gray3" />

</android.support.v4.widget.DrawerLayout>

布局代码2:里层嵌套Toolbar

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#30469b"
        android:paddingTop="@dimen/toolbar_padding_top"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="ToolBar版"
            android:textSize="20sp" />

    </android.support.v7.widget.Toolbar>

    <!--内容显示布局-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/goToActionBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="切换到ActionBar版" />
    </RelativeLayout>

</LinearLayout>

Style样式:无ActionBar

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

主程序代码:除了要在onCreate()里面初始化 DrawerLayout、NavigationView、Toolbar控件 即initViews(),还要在onCreate()里面添加手机系统版本判断和相应的样式适配initImmersive()

private void initViews() {
        mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerlayout);
        mNagigationView = (NavigationView) findViewById(R.id.id_navigationview);
        mNagigationView.inflateHeaderView(R.layout.header_nav);
        mNagigationView.inflateMenu(R.menu.menu_nav);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mBtn = (Button) findViewById(R.id.goToActionBar);
        mToolbar.setTitle("");
        if (mToolbar != null) {
            setSupportActionBar(mToolbar);
        }
        ActionBarDrawerToggle mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close);
        mActionBarDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
           



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android通知栏沉浸式/透明化完整解决方案,root不完整解决方法
  • Android中的沉浸式状态栏效果,android沉浸状态栏

相关文章

  • 2017-05-228.2.2 Bitmap引起的OOM问题
  • 2017-05-26MultiTouch————多点触控,伸缩图片,变换图片位置,
  • 2017-11-18android 上传头像
  • 2017-05-26android开发之路01,android之路01
  • 2017-05-26redis master-slave 切换演练
  • 2017-05-26Android Studio:Failed to resolve ***,androidresolve
  • 2017-05-228.3.3 Paint API之—— MaskFilter(面具)
  • 2017-05-26自定义图片轮播框架。也是作为依赖库使用的哦,自定义框架
  • 2017-05-26Android学习--RelativeLayout相对布局
  • 2017-05-227.5.3 Android 4.4后WebView的一些注意事项

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 老人桌面===花花绿绿的桌面,老人桌面
    • android关于线程的那些事,android那些事
    • 极其简单的搭建eclipse的android开发环境,搭建eclipseandroid
    • Android versionCode和versionName的区别,androidversioncode
    • popupwindow展示,popupwindow
    • 手机安全卫士——病毒查杀,安全卫士病毒查杀
    • linux设备驱动程序之时钟管理(2)----又见结构
    • Android 学习2----页面布局的学习,android2----
    • 谈谈LoveLive SIF以及即将诞生的LL练习器,lovelivesif
    • 服务器DELL R710配置安装centos经验之谈

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有