1.繪製矩形漸變框
android:type=[“linear” | “radial” | “sweep”] //共有3中漸變類型,線性漸變(默認)/放射漸變/掃描式漸變
android:angle=“integer” //漸變角度,必須爲45的倍數,0爲從左到右,90爲從上到下
android:centerX=“float” //漸變中心X的相當位置,範圍爲0~1
android:centerY=“float” //漸變中心Y的相當位置,範圍爲0~1
android:startColor=“color” //漸變開始點的顏色
android:centerColor=“color” //漸變中間點的顏色,在開始與結束點之間
android:endColor=“color” //漸變結束點的顏色
android:gradientRadius=“float” //漸變的半徑,只有當漸變類型爲radial時才能使用
android:useLevel=[“true” | “false”] /> //使用LevelListDrawable時就要設置爲true。設爲false時纔有漸變效果
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--實現應用背景顏色漸變-->
<gradient
android:startColor="#3faae7"
android:endColor="#4e90fb"
android:angle="90"/>
</shape>
效果圖:
2.圓角矩形。設置圓角角度和填充的顏色
solid用以指定內部填充色。
corners定義圓角。
android:radius=“dimension” //全部的圓角半徑
android:topLeftRadius=“dimension” //左上角的圓角半徑
android:topRightRadius=“dimension” //右上角的圓角半徑
android:bottomLeftRadius=“dimension” //左下角的圓角半徑
android:bottomRightRadius=“dimension” /> //右下角的圓角半徑
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="35dp" />
<solid
android:color="#4e90fb"/>
</shape>
效果圖:
3.圓角矩形的邊框
stroke描邊屬性,可以定義描邊的寬度,顏色,虛實線等
android:width=“dimension” //描邊的寬度
android:color=“color” //描邊的顏色
// 以下兩個屬性設置虛線
android:dashWidth=“dimension” //虛線的寬度,值爲0時是實線
android:dashGap=“dimension” //虛線的間隔
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/dp_8" />
<stroke
android:width="@dimen/dp_2"
android:color="#6eb2b2b2"/>
</shape>
效果圖
4.針對底部導航欄圖標變色操作,設置默認圖標,然後點擊之後的圖標
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@mipmap/user1"/>
<item android:drawable="@mipmap/user"/>
</selector>
在layout.xml中調用
<RadioButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableTop="@drawable/selector_main_mine"
android:textColor="@color/color_radiobutton"
android:layout_centerVertical="true"
android:layout_weight="1"
android:text="@string/three"
android:textSize="@dimen/sp_12"
android:button="@null"
android:gravity="center" />
效果圖