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