今天就想记录记录实战项目中为了实现一些效果写的drawable文件,什么按钮的背景,点击效果selector什么的,啧啧啧放张我爱的仙剑四图片啊哈哈哈~(其实我最爱菱纱,梦璃那么美,我真正的女神呐)
图片取自网络-
selector_tab_模块.xml(一般项目中的tab点击,就会切换一张图片)
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/tab_me_selected" android:state_selected="true" />
<item android:drawable="@mipmap/tab_me_normal" />
</selector></pre> -
bg_rec200_颜色.xml(一个弧形的背景,有时候一段文字的背景,或者按钮的背景,随需求改变颜色就可以哒,还有角度,边界间距也是随需求更改)
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners
android:radius="200dp" />
<solid android:color="@color/Gray05" />
</shape></pre> -
selector_rec200_pink2gray.xml(像按钮的点击,按下也许是不同的背景,边界、角度随需求变化,我的取名方法是对我来说比较好辨认的方法)
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="200dp" />
<solid android:color="@color/Purple02" />
</shape>
</item>
</layer-list>
</item>
<item android:state_enabled="false">
<layer-list>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="200dp" />
<solid android:color="@color/Gray03" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="200dp" />
<solid android:color="@color/Purple01" />
</shape>
</item>
</layer-list>
</item>
</selector>
</pre> -
selector_rbtn_模块.xml(RadioButton的自定义背景)
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@mipmap/icon_select" />
<item
android:state_checked="true"
android:drawable="@mipmap/icon_selected" />
</selector></pre> -
selector_radio_bg.xml
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/selector_rec4_purple" android:state_checked="true" />
<item android:drawable="@drawable/selector_rec4_purple" android:state_selected="true" />
<item android:drawable="@color/White" />
</selector> </pre> -
rating_bar.xml(设置RatingBar的progressDrawable)
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@mipmap/icon_star_hole" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@mipmap/icon_star_hole" />
<item android:id="@android:id/progress"
android:drawable="@mipmap/icon_star_yellow" />
</layer-list></pre> -
bg_rec4_stroke_purple.xml
截图
<pre><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="4dp" />
<stroke
android:width="1dp"
android:color="@color/Purple01" />
</shape></pre>
网友评论