Android 4.4版本的Material Design设计方法

Material_Design


ThemeColors.png

自从Android 5.0推出后其所运用的Material Design设计出来的界面深受广大用户的喜爱,但只有android 5.0及以上的版本支持这用法,对于android 5.0以下的手机,又该如何呢?

经摸索,有下面方法可以设置:

  • 步骤
    -- 1 build.gradle文件内的 minSdkVersion >= 19

-- 2 在styles.xml添加如下几行:

<!--设置状态栏为半透明-->
<item name="android:windowTranslucentStatus">true</item>
<!--避免控件都顶到状态栏上-->
<item name="android:fitsSystemWindows">true</item>

完整代码如下:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">#4386f4</item>
        <item name="colorPrimaryDark">#3468d6</item>
        <item name="colorAccent">#313131</item>
        <!--设置状态栏为半透明-->
        <item name="android:windowTranslucentStatus">true</item>
        <!--避免控件都顶到状态栏上-->
        <item name="android:fitsSystemWindows">true</item>
    </style>
</resources>

-- 3 设置Activity布局文件的根节点的背景为相应的colorPrimaryDark的颜色

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:background="@color/colorPrimaryDark"
    tools:context="com.nlte.theme.MainActivity">
</RelativeLayout>

-- 4 加入一个布局文件,并将其背景设置为喜欢的颜色,之后的控件就写在该布局文件内:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:background="@color/colorPrimaryDark"
    tools:context="com.nlte.theme.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/windowBackground">
    </LinearLayout>
</RelativeLayout>

OK!大功告成,有木有小激动呢!

结果图.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值