Android How to customize button effects _android

Source: Internet
Author: User

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"/> &LT;/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.

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.