控件美化

来源:互联网 发布:知乎话题精华 mobi 编辑:程序博客网 时间:2024/05/16 11:47

具体代码如下:

main.xml:

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:layout_width="fill_parent"   
  4.     android:layout_height="fill_parent"   
  5.     >   
  6.     <LinearLayout   
  7.         android:layout_width="match_parent"   
  8.         android:layout_height="wrap_content"   
  9.         android:orientation="vertical" >   
  10.         <Button   
  11.             android:layout_width="match_parent"   
  12.             android:layout_height="wrap_content"   
  13.             android:layout_margin="10dp"   
  14.             android:text="button1"   
  15.             android:background="@drawable/button_selector"   
  16.             />      
  17.         <Button   
  18.             android:layout_width="match_parent"   
  19.             android:layout_height="wrap_content"   
  20.             android:layout_margin="10dp"   
  21.             android:text="button2"   
  22.             android:background="@drawable/button_selector"   
  23.             />    
  24.         <Button   
  25.             android:layout_width="match_parent"   
  26.             android:layout_height="wrap_content"   
  27.             android:layout_margin="10dp"   
  28.             android:text="button3"   
  29.             android:background="@drawable/button_selector"   
  30.             />    
  31.     </LinearLayout>   
  32.     <ImageView   
  33.         android:layout_width="wrap_content"   
  34.         android:layout_height="wrap_content"   
  35.         android:src="@drawable/bg2"   
  36.         android:focusable="false"   
  37.         />   
  38. </RelativeLayout> 

button_selector.xml:

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <selector   
  3.     xmlns:android="http://schemas.android.com/apk/res/android">   
  4.     <item android:state_pressed="true" >   
  5.         <shape>   
  6.             <!-- 实心,即填充 -->   
  7.             <solid android:color="#8470FF"/>   
  8.             <!-- 描边 -->   
  9.             <stroke   
  10.                 android:width="2dp"   
  11.                 android:color="#FFFF00"/>   
  12.             <!-- 圆角 -->   
  13.             <corners   
  14.                 android:radius="5dp" />   
  15.             <padding   
  16.                 android:left="10dp"   
  17.                 android:top="10dp"   
  18.                 android:right="10dp"   
  19.                 android:bottom="10dp" />   
  20.         </shape>   
  21.     </item>   
  22.  
  23.     <item>         
  24.         <shape>   
  25.             <!-- 实心,即填充 -->   
  26.             <solid android:color="#8470FF"/>   
  27.             <corners   
  28.                 android:radius="5dp" />   
  29.             <padding   
  30.                 android:left="10dp"   
  31.                 android:top="10dp"   
  32.                 android:right="10dp"   
  33.                 android:bottom="10dp" />   
  34.         </shape>   
  35.     </item>   
  36. </selector> 
原创粉丝点击