Android Diary-Customizing button effects

Source: Internet
Author: User

Android Native button is how ugly, the effect is how monotonous, everyone is also visible.
To make an app without using a button, a nice-looking button with good effect and appearance
This time we'll talk about how to use drawable XML files to get some nice custom styles.

First, appearances .
Boxy in the app, the gray bottom black button is hard to see, we want to see the rounded corners, color, white text (according to your personal aesthetic can also be other styles).
The first is to create a new button in layout.
Then create a new drawable resource file in the Drawable folder.
You might as well be named shape
Add a new item node in a selector node
Add a style to the item node

<?xml version= "1.0" encoding= "Utf-8"?><selector xmlns:android="Http://schemas.android.com/apk/res/android">    <item>        <shape>            <!--fill color (bright green)- -            <solid android:color="#28baa7" />            <!--set the four corners of the button arc--            <!--Android:radius arc radius--            <corners Android:radius="5dip" />            <!--The spacing between the text and the button boundary in the Padding:button            <paddingandroid:left="10DP"android:top="10DP"android: right ="10DP"android:bottom="10DP" />                                                        </shape>    </Item></selector>

If you want to do the post-click button style
Add an item node again
This is the whole drawable.

<?xml version= "1.0" encoding= "Utf-8"?><selector xmlns:android="Http://schemas.android.com/apk/res/android">    <item android:state_pressed="true">        <shape>            <!--fill Color (white) --            <solid android:color="#aaa" />            <!--set the four corners of the button arc--            <!--Android:radius arc radius--            <corners Android:radius="5dip" />            <!--The spacing between the text and the button boundary in the Padding:button            <paddingandroid:left="10DP"android:top="10DP"  Android:right="10DP"android:bottom="10DP" />                                                                        </shape>    </Item>    <item>        <shape>            <!--fill color (bright green)- -            <solid android:color="#28baa7" />            <!--set the four corners of the button arc--            <!--Android:radius arc radius--            <corners Android:radius="5dip" />            <!--The spacing between the text and the button boundary in the Padding:button            <paddingandroid:left="10DP"android:top="10DP"android: right ="10DP"android:bottom="10DP" />                                                        </shape>    </Item></selector>

Such a style is generally bright green around the rounded corners
White rounded corners when clicked

There are a lot of things to look for in addition to clicking.

Okay, here's the layout file setup.

 <Button        android:layout_width="150dp"        android:layout_height="wrap_content"        android:text="button"        android:textColor="#fff"        android:background="@drawable/shape"        android:id="@+id/btn"        android:layout_gravity="center_horizontal" />

This sets the text to center white

Well, a better-looking button was born.

Android Diary-Customizing button effects

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.