MainActivity is as follows:
Copy codeThe Code is as follows: package cn. testshape;
Import android. OS. Bundle;
Import android. app. Activity;
/**
* Demo description:
* Use of custom shapes
*/
Public class MainActivity extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}
}
Main. xml is as follows:Copy codeThe Code is 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 shapes"
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 codeThe Code is 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 codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<! -- Define the rectangle of a rectangle -->
<Shape xmlns: android = "http://schemas.android.com/apk/res/android"
Android: shape = "rectangle">
<! -- Define border color -->
<Solid android: color = "# d1d1d1"/>
<! -- Define the arc radians -->
<Corners
Android: bottomLeftRadius = "4dp"
Android: bottomRightRadius = "4dp"
Android: topLeftRadius = "4dp"
Android: topRightRadius = "4dp"
/>
</Shape>
Pressed_shape.xml is as follows:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<! -- Define the rectangle of a rectangle -->
<Shape xmlns: android = "http://schemas.android.com/apk/res/android"
Android: shape = "rectangle">
<! -- Define border color -->
<Solid android: color = "#7bb3f8"/>
<! -- Define the arc radians -->
<Corners
Android: bottomLeftRadius = "4dp"
Android: bottomRightRadius = "4dp"
Android: topLeftRadius = "4dp"
Android: topRightRadius = "4dp"
/>
</Shape>
Textcolor_selector.xml is as follows:Copy codeThe Code is 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" type = "codeph" text = "/codeph"/>
</Selector>