View
Create a Colors.xml file to define two colors
1. <resources>
2. <color name="blue_pressed"> @android: Color/holo_blue_dark </color>
3. <color name="blue_normal">@ Android:color/holo_blue_light</color>
4. </resources>
Here we use the holo tones of Android:
1. <!--A dark holo shade of blue
2. <color name="Holo_blue_dark"># ff0099cc</color>
3. <!--A light holo shade of blue
4. <color name="holo_blue_light"># Ff33b5e5</color>
Create a Dimen.xml file that defines the fillet value and the height of the shadow, see
1. <resources>
2.&NBSP; <dimen &NBSP; name = "Corner_radius" > 4DP </DIMEN>
3. <dimen name="layer_padding"> 3dp< <dimen>
4. </resources>
We use shape to define the button background to create the Rect_pressed.xml drawable file
1. <shape xmlns:android="http://schemas.android.com/apk/res/ Android "
2. android:shape="Rectangle">
3. <corners android:radius="@dimen/corner_radius" />
4. <solid android:color="@color/blue_ Pressed " />
5. </shape>
Create a drawable file for rect_normal.xml files.
1. <layer-list xmlns:android="http://schemas.android.com/apk /res/android ">
2. <item android:drawable="@drawable/rect_pressed" />
3.
4. <item android:bottom="@dimen/layer_padding" >
5. <shape android:shape="Rectangle" C15>>
6.&NBSP; <corners &NBSP; android:radius = " @dimen/corner_radius " &NBSP; />
7. <solid android:color="@color/blue_normal" />
8. </shape>
9. </item>
Ten. </layer-list>
Defines the selector for the button. Create a Flat_selector.xml file.
1. <selector xmlns:android="http://schemas.android.com/apk/ Res/android ">
2.&NBSP; &NBSP;&NBSP; <item &NBSP; android:state_pressed = " true " &NBSP; = "@ drawable/rect_pressed " />
3. <item android:drawable="@drawable/rect_normal" />
4. </selector>
Define the button setting background to Flat_selector.
1. <button
2. android:layout_width="Fill_parent"
3. android:layout_height="Wrap_content"
4. android:background="@drawable/flat_selector"
5. android:textcolor="@android: Color/white"
6. android:text="Say Hello" />
Android Flat button