How ugly the Android button is, and how monotonous the effect is, is obvious to everyone.
To do an app without the use of buttons, a good-looking button without the effect and appearance, this is mainly to tell you how to use drawable XML file to get some good-looking custom style.
First, appearances .
In app boxy, the gray bottom black word button is very difficult to see, we want to see is rounded, color, white (according to your personal aesthetic can also be other styles).
The first is to create a new button in the layout, and then create a new drawable resource file in the Drawable folder, you might name it as shape, add a new item node in a selector node, adding 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>
<!--filled colors (bright green)-->
<solid android:color=" #28baa7 "/>
<!--set the four corners of the button arc-->
<!--android:radius arc radius-->
<corners android:radius=" 5dip "/ >
<!--padding:button inside the text and button boundaries-->
<padding
android:left= "10DP"
android: top= "10DP"
android:right= "10DP"
android:bottom= "10DP"
/>
</shape>
</item >
</selector>
If you want to do the style of the Post click button, add an item node and the entire drawable is the same.
<?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:c Olor= "#aaa"/> <!--set button Four Corners arc--> <!--android:radius arc radius--> <corners android:radius= "5dip
"/> <!--Padding:button the spacing between the text and button boundaries--> <padding android:left=" 10DP "android:top=" 10DP "
android:right= "10DP" android:bottom= "10DP"/> </shape> </item> <item> <shape> <!--filled color (bright green)--> <solid android:color= "#28baa7"/> <!--setting button Four Corners arc--> <!--Android:ra Dius arc radius--> <corners android:radius= "5dip"/> <!--Padding:button the spacing between the text and the button boundary--> Ding android:left= "10DP" android:top= "10DP" android:right= "10DP" android:bottom= "10DP"/> </SHAPE&G
T
</item> </selector>
Such a style is generally bright green round corners, when clicked is the white fillet, in addition to the click of a lot of circumstances, please use your own search, is similar
Okay, here's the setup for the layout file.
<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 set the text to the center of the white, OK, a more beautiful button is so born
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.