Android5.0、6.0新特性(1)

    xiaoxiao2021-03-25  194

    主题样式自定义状态栏、标题栏、导航栏的颜色

    MaterialTheme配色方案:http://www.materialpalette.com

    1.1 创建相应的样式文件

    右键点击res -> 选择Android resource file -> 设置名称styles,设置存放目录values-v21,设置支持的版本21

    1.2 将values目录下的styles.xml文件中的代码拷贝过来,修改样式主题是android:Theme.Material

    如果想要使用白色主题使用android:Theme.Material.Light <style name="AppTheme" parent="android:Theme.Material.Light"></style>

    1.3 手动更改相应的样式

    <style name="AppTheme" parent="android:Theme.Material.Light"> <!-- Customize your theme here. --> <item name="android:colorPrimary">#FF0000</item> <item name="android:colorPrimaryDark">#00FF00</item> <item name="android:colorAccent">@color/colorAccent</item> </style>

    1.4 通过主题编辑页面进行操作

    点击上部Open editer选项进入主题编辑页面,可以直观的查看设置的样式

    高度和阴影效果

    官网介绍:https://developer.android.com/intl/zh-tw/training/material/shadows-clipping.html View增加了高度的概念,高度大的View会覆盖在高度小的View之上,并带有阴影效果: View高度有2个因素组成:View高度 = elevation + translationZ

    2.1 elevation表示view的高度,高度越大,阴影越大,可以在xml中直接使用属性,也可以在代码中使用view.setEvelvation();

    海拔阴影高度属性,高度不能超过父窗体,超过父窗体的阴影部分会被截取掉,并且设置阴影高度的控件背景不能是透明的 android:elevation="30dp" 使用 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="10dp" android:background="#FFFFFF" android:text="阴影"/> </RelativeLayout>

    2.2 通过设置elevation属性实现控件重叠效果

    将图片存放到mipmap-hdpi(用来替换drawable的,它在屏幕处理的时候效率会更高)目录中 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="10dp" android:background="#FFFFFF" <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/head" android:background="#FFFFFF" android:elevation="15dp" /> </RelativeLayout>

    2.3 TranslationZ设置

    elevation是设置阴影,TranslationZ是z轴上移动的距离(可以通过TranslationX属性进行验证),因为z轴移动所以动态带有阴影 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:translationZ="20dp" android:background="#FFFFFF" android:text="阴影"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/head" android:background="#FFFFFF" android:translationZ="25dp"/> </RelativeLayout>
    转载请注明原文地址: https://ju.6miu.com/read-3013.html

    最新回复(0)