After Android background is set to color, it becomes textview.

Source: Internet
Author: User

Who will think of all kinds of buttons in the webpage when using the button? Do you want to design that effect? The answer is yes. Android is very powerful. However, the first step today is a headache. Everything is from simplicity to simplicity, just like the design of the button. The first step is to set the background for the button. I did the same. However, after the background is set to the color, the button becomes a textview, and the height is the same as that of the text. This is definitely not the result I want. Then Baidu gets the result: paste the Link first. The android button already has an implementation by default. It uses the State List internally (for details, read the official documentation and quietly tell you that you can design your own button after reading this chapter, the Directory of the document is Dev guid ------ drawable resources). Now we use Android: drawable = "@ color/red" to overwrite the original style, so this tragedy occurs. Solution: 1. Define a drawable resource of the XML type. For example:

Res/values/colors. xml ----------------------------------

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Color name = "red"> # ff0000 </color>
<Color name = "green"> #00ff00 </color>
<Color name = "blue"> # 0000ff </color>
</Resources>

Res/drawable/button. xml ---------------------------- ①

<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "true"
Android: drawable = "@ color/Blue"/> <! -- Pressed -->
<Item Android: state_focused = "true"
Android: drawable = "@ color/red"/> <! -- Focused -->
<Item Android: drawable = "@ color/Green"/> <! -- Default -->
</Selector>

Use

<Button
Android: Id = "@ + ID/Show"
Android: layout_width = "fill_parent"
Android: layout_height = "40dip"
Android: text = "show"
Android: Background = "@ drawable/button"
/>

Then, set the height of the button to have its own display style.

The second solution is to change the drawable at location 1 to an image, which can also have a fixed height.

Said these, should give you a reference: http://blog.csdn.net/zhanghw0917/article/details/5630538

After completing the above operations, do you feel satisfied? This should not be our end point, but the starting point.

Now, we can implement some complex buttons. If you don't talk much about them, I will also post the link:

Http://blog.csdn.net/xjanker2/article/details/6222690

 

Related Article

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.