自定义button样式,圆角按钮

自定义button样式,圆角按钮,先上图
自定义button样式,圆角按钮_第1张图片

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="15dp"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        style="@style/common_button_blue_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Button1" />

    <Button
        style="@style/common_button_red_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Button2" />

LinearLayout>

styles.xml




    
    -- Application theme. -->
    
    
    

selector_blue_corners_button.xml


<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/shape_blue_corners_button_pressed" />
    <item android:state_pressed="false" android:drawable="@drawable/shape_blue_corners_button" />
selector>

shape_blue_corners_button_pressed.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="10.0px" />

    <solid android:color="@color/blue_dark" />

shape>

shape_blue_corners_button.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="10.0px" />

    <solid android:color="@color/blue_light" />

shape>

color.xml

<color name="blue_dark">#009ACD
<color name="blue_light">#00B2EE
<color name="red_dark">#ffb52121
<color name="red_light">#ffcd2222

有些没列出来,直接上demo吧
buttoncorner

你可能感兴趣的:(android开发)