Android开发之漂亮Button样式
2016-12-26 本文已影响27948人
gyymz1993
开发中各种样式的Button,其实这些样式所有的View都可以共用的,可能对于你改变的只有颜色
所有的都是用代码实现
150CC48D90067F05BFAC966F4EE3E21D.jpg边框样式,给你的View加上边框
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:background="@drawable/border_line_while"
android:gravity="center"
android:text="边框样式"
/>
边框样式border_line_while.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:useLevel="false"
>
<solid android:color="@null"/>
<padding android:left="1dip"
android:right="1dip"
android:bottom="1dip"/>
<stroke android:width="1dip"
android:color="@color/theme_red"
/>
<!--边框宽度-->
<size android:width="15dip"
android:height="15dip"
/>
<!--边框-->
</shape>
圆角Button
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:background="@drawable/btn_bg_red"
android:gravity="center"
android:text="圆角Button"
/>
圆角样式btn_bg_red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/theme_red"/>
<corners android:topLeftRadius="10dip"
android:topRightRadius="10dip"
android:bottomRightRadius="10dip"
android:bottomLeftRadius="10dip" />
<!--圆角矩形白色背景-->
</shape>
点底色的圆角Button,其实综合上面的就可以自己写
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:background="@drawable/check_border"
android:gravity="center"
android:text="带边框颜色的Button"
/>
点底色的圆角Button样式check_border.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item android:state_pressed="true">-->
<!--<shape android:shape="rectangle">-->
<!--<stroke android:width="1px" android:color="@color/color_light_grey" />-->
<!--<corners android:radius="3dp" />-->
<!--<solid android:color="@color/color_detach_line" />-->
<!--</shape>-->
<!--</item>-->
<item>
<shape android:shape="rectangle">
<stroke android:width="1px" android:color="@color/theme_red" />
<corners android:radius="10dp" />
<solid android:color="@color/color_check_bg" />
</shape>
</item>
</selector>
带点击圆角状态的Button,依赖样式文件
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:background="@drawable/btn_nor_down"
android:gravity="center"
android:text="带点击状态的Button"
/>
带点击圆角状态的Button样式btn_nor_down.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/check_border" />
<item android:state_focused="true" android:drawable="@drawable/check_border" />
<item android:state_checked="true" android:drawable="@drawable/check_border" />
<item android:state_selected="true" android:drawable="@drawable/check_border"/>
<item android:drawable="@drawable/btn_bg_red"></item>
</selector>
带点击状态的Button,这个不依赖圆角样式
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:background="@drawable/btn_bottom_confirm_bg"
android:gravity="center"
android:text="带点击状态的Button"
/>
带点击圆角状态的Button样式btn_bottom_confirm_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#f5f5f5"/>
<stroke android:width="1px"
android:color="#cfcfd2"/>
<padding android:top="1px"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white"/>
<stroke android:width="1px"
android:color="#cfcfd2"/>
<padding android:top="1px"/>
</shape>
</item>
</selector>
原形数字提醒
<Button
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="20dip"
android:background="@drawable/hint_superscript_red"
android:gravity="center"
android:text="数字提醒"
/>
原形数字提醒样式hint_superscript_red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solid android:color="@color/white"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<!--描边 红色边框-->
<stroke android:width="1dp"
android:color="@color/theme_red"
/>
<size android:width="15dp"
android:height="15dp"
/>
</shape>
请求网络数据等待框
<ProgressBar
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="20dp"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progresstyle"
android:indeterminateTintMode="src_in"/>
请求网络数据等待框样式progresstyle.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080.0" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<gradient
android:centerY="0.50"
android:endColor="@color/theme_red"
android:startColor="@color/white"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
进度条
<ProgressBar
android:id="@+id/my_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:max="10"
android:progress="3"
android:progressDrawable="@drawable/progressbar_color"/>
进度条样式progressbar_color.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 背景 gradient是渐变,corners定义的是圆角 -->
<item android:id="@android:id/background">
<shape>
<corners android:radius="3dp"/>
<solid android:color="@color/theme_red" />
</shape>
</item>
<!-- 第二条进度条颜色 -->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="3dp"/>
<gradient
android:angle="90.0"
android:centerColor="#ac6079"
android:centerY="0.45"
android:endColor="#6c213a"
android:startColor="#FF51AAE6" />
</shape>
</clip>
</item>
<!-- 进度条 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="3dp"/>
<solid android:color="#FF51AAE6" />
</shape>
</clip>
</item>
</layer-list>
底部线条EditText
<EditText
android:text="底部线条EditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/edit_for_line_bg"
/>
底部线条EditText样式edit_for_line_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material">
<selector>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/>
</selector>
</inset>