Mainactivity is as follows:
Copy Code code as follows:
Package cn.testshape;
Import Android.os.Bundle;
Import android.app.Activity;
/**
* Demo Description:
* Use of custom shape
*/
public class Mainactivity extends activity {
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
}
Main.xml is as follows:
Copy Code code as follows:
<relativelayout
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"
>
<button
Android:layout_width= "250dip"
android:layout_height= "50dip"
android:text= "Test the use of custom shape"
android:background= "@drawable/background_selector"
Android:textcolor= "@drawable/textcolor_selector"
Android:layout_centerinparent= "true"
android:gravity= "Center"
/>
</RelativeLayout>
Background_selector.xml is as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:drawable= "@drawable/pressed_shape" android:state_pressed= "true"/>
<item android:drawable= "@drawable/default_shape"/>
</selector>
Default_shape.xml is as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<!--define Rectangular rectangle-->
<shape xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shape= "Rectangle" >
<!--define Border color-->
<solid android:color= "#d1d1d1"/>
<!--define fillet radians-->
<corners
Android:bottomleftradius= "4DP"
Android:bottomrightradius= "4DP"
Android:topleftradius= "4DP"
Android:toprightradius= "4DP"
/>
</shape>
Pressed_shape.xml is as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<!--define Rectangular rectangle-->
<shape xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shape= "Rectangle" >
<!--define Border color-->
<solid android:color= "#7bb3f8"/>
<!--define fillet radians-->
<corners
Android:bottomleftradius= "4DP"
Android:bottomrightradius= "4DP"
Android:topleftradius= "4DP"
Android:toprightradius= "4DP"
/>
</shape>
Textcolor_selector.xml is as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns: Android= "Http://schemas.android.com/apk/res/android" >
<item android:color= "#ffffff" Android:state_ Pressed= "true"/>
<item android:color= "#000000"/>
</selector>