自定义Button样式

作者:追风剑情 发布于:2016-5-6 11:22 分类:Android

一、新建按钮样式button_styles.xml

项目上点击右键->New->Android XML File

111111111.png

333333.png

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <item android:state_pressed="true" android:drawable="@drawable/wallet_base_pwdpay_submit_bg_pressed" />
  4. <item android:state_focused="true" android:drawable="@drawable/wallet_base_pwdpay_submit_bg_pressed" />
  5. <item android:drawable="@drawable/wallet_base_pwdpay_submit_bg_normal" />
  6. </selector>

二、设置Button的android:background属性

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical"
  6. android:paddingBottom="@dimen/activity_vertical_margin"
  7. android:paddingLeft="@dimen/activity_horizontal_margin"
  8. android:paddingRight="@dimen/activity_horizontal_margin"
  9. android:paddingTop="@dimen/activity_vertical_margin"
  10. tools:context="com.test.androidtest.MainActivity$PlaceholderFragment" >
  11.  
  12. <Button android:id="@+id/btn"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:background="@drawable/button_styles"
  16. android:text="Button"
  17. android:padding="10dp"
  18. android:onClick="onClick" />
  19.  
  20. </LinearLayout >

运行测试

22222.png

 

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号