Android flat button and android flat button

Source: Internet
Author: User

Android flat button and android flat button

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 color 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 and define the rounded corner value and shadow height. For details, see

1. <resources>

2. <dimen 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 drawable file of rect_pressed.xml.

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 the drawable file of rect_normal.xml file.

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">

6. <corners android: radius = "@ dimen/corner_radius"/>

7. <solid android: color = "@ color/blue_normal"/>

8. </shape>

9. </item>

10. </layer-list>

 

Define selector for the button. Create the flat_selector.xml file.

1. <selector xmlns: android = "http://schemas.android.com/apk/res/android">

2. <item android: state_pressed = "true" android: drawable = "@ drawable/rect_pressed"/>

3. <item android: drawable = "@ drawable/rect_normal"/>

4. </selector>

Define the button to set the 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"/>


How does android hide buttons?

Button. setVisibility (View. INVISIBLE); indicates hiding;
Reference: hi.baidu.com/...5.html

Button arrangement in the android Layout

This can completely meet your requirements, and the screen can be changed.
<LinearLayout android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: orientation = "horizontal"> <Button android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1"/> <Button android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1"/> <Button android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1"/> <Button android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1"/> </LinearLayout>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.