2013-12-14 99 views

回答

-1

創建三個.XML在res/drawable

button_normal.xml

<?xml version="1.0" encoding="utf-8"?> 

<solid android:color="#FFFFFF" /> 

<corners android:radius="3dip" /> 

<stroke 
    android:width="1dip" 
    android:color="@android:color/transparent" /> 

button_focused.xml

<solid android:color="#FFFFFF" /> 

<corners android:radius="3dip" /> 

<stroke 
    android:width="1dip" 
    android:color="@android:color/transparent" /> 

button_background.xml

<?xml version="1.0" encoding="utf-8"?> 

<item android:drawable="@drawable/button_normal.xml" android:state_window_focused="false"/> 
<item android:drawable="@drawable/button_focused" android:state_focused="true"/> 

2.組後臺與您layout.xml或代碼​​

button.setBackgroundDrawable(getResources().getDrawable(
      R.drawable.button_background.xml)); 

的更多信息:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape