Android 实现侧边栏之状态栏颜色适配

在Android开发中,遇到低版本手机状态栏颜色不自动适配的问题。本文提供了一种解决方法,通过布局和主题设置,结合Material Design组件,实现状态栏颜色的统一和全屏显示,适用于包括低版本设备在内的各种Android手机。
摘要由CSDN通过智能技术生成

最近开发中老师会遇到toobar和status bar这个梗。之前没有多大在意,因为我发现用上toolbar时,手机会自动更改状态栏的颜色,后来我特意用别的低版本手机试了试,简直是个坑。
后来一直想找个最终的适配办法。好像一直没有很好的解决问题,后来弄出了以下方法。虽然有不合理的地方,不过对效果来说没什么问题了,包括低版本的手机也能显示良好。

这里主要是通过布局已经主题来实现的。
这里用到了material design中的NavigationView ,如果对NavigationView 不熟悉可以看这里:http://blog.csdn.net/lmj623565791/article/details/46405409
效果图:
这里写图片描述

主布局:
这里主要是这个属性:android:fitsSystemWindows="true" 意思是说使内容扩展到状态栏。不然后状态栏不会有变化,尤其想让图片全屏显示时。其它的没什么特别要注意的地方。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/id_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#0cbcf6"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        <TextView
            android:id="@+id/id_tv_content"
            android:layout_width="
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值