效果图:
样式如下:
rounded_corner_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="@color/lightgray" />
<corners android:radius="10dp" />
<solid android:color="@android:color/white"/>
</shape>
rounded_corner_btn_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<stroke android:width="2dp" android:color="@color/orange" />
<corners android:radius="10dp" />
<solid android:color="@color/orange"/>
</shape>
</item>
<item android:state_focused="true" android:drawable="@drawable/rounded_corner_shape" />
<item android:drawable="@drawable/rounded_corner_shape" />
</selector>
style.xml
<resources>
<style name="RoundedCornerView">
<item name="android:background">@drawable/rounded_corner_shape</item>
<item name="android:cacheColorHint">@color/transparent</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:paddingLeft">12dp</item>
<item name="android:paddingRight">12dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="RoundedCornerBtn" parent="RoundedCornerView">
<item name="android:background">@drawable/rounded_corner_btn_selector</item>
<item name="android:gravity">left|center_vertical</item>
<item name="android:textColor">@color/gray</item>
</style>
<style name="RoundedCornerBtnWithRightArrow" parent="RoundedCornerBtn">
<item name="android:drawableRight">@drawable/right_arrow</item>
</style>
</resources>
在layout中为按钮设置样式
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="带箭头的按钮"
android:textSize="20sp"
style="@style/RoundedCornerBtnWithRightArrow"/>