用TextView自定义按钮

        • 主xml文件
        • 背景选择器drawablegreen_selector_buttonxml
          • 背景drawablecorners_all_edittext_green_darkxml
          • 背景drawablecorners_all_edittext_greenxml

主xml文件

RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:orientation="horizontal"
    android:layout_gravity="center"
    android:layout_marginTop="20dip"
    android:paddingLeft="15dip"
    android:paddingRight="15dip"
    >

    <TextView  android:id="@+id/loginButton" android:layout_width="match_parent" android:layout_height="match_parent" android:text="登录" android:gravity="center" android:layout_centerInParent="true" style="@style/text_s32_ffffff" //自定义按钮核心代码 android:background="@drawable/green_selector_button" />
</RelativeLayout>

背景选择器:drawable/green_selector_button.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- selector:背景选择器 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- android:state_pressed:点击时背景 -->
    <item android:state_pressed="true" android:drawable="@drawable/corners_all_edittext_green_dark" />
    <!-- 默认时的背景--> 
    <item android:drawable="@drawable/corners_all_edittext_green" />
</selector>
背景:drawable/corners_all_edittext_green_dark.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="5dp">
    <solid android:color="@color/wechat_background_green_dark" />  
    <corners android:radius="3dp" />
</shape>
背景:drawable/corners_all_edittext_green.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="5dp">
    <solid android:color="@color/wechat_background_green" />  
    <corners android:radius="3dp" />
</shape>

你可能感兴趣的:(android,textview,按钮)