Android Developer Mac-style button

Source: Internet
Author: User

Recently tried to play Android development, do a gadget, always feel the default button style is too bad, see the Internet several iphone screenshots, feel the button a little bit feel, just want to copy a come over ... There is no technical content, just a bad memory, recorded.

The preparation on Photoshop

In a simple way, set the background picture.

First gradient fill Rounded rectangle (radius 4 or so), the beginning and end color of the gradient itself set, but the transition position I tried, about the figure 1 above, in 40% and 60% increased two color, the value of the difference between the end of 1/3 and 2/3.
Make three-dimensional effects and shadows, as shown in 2
Make a border line, as shown in 3
Then tune the two bright and darker (unused iphone does not know the focus and what it looks like when I'm lazy to get a change of tone) button.
Apply To Button

Define a model file in drawable

<?xml version= "1.0" encoding= "Utf-8"?>
<selector
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "true" android:drawable= "@drawable/game_button_pressed"/>
<item android:state_focused= "true" android:drawable= "@drawable/game_button_focused"/>
<item android:drawable= "@drawable/game_button_normal"/>
</selector>

Then the button's background points to it, it's over ~ ~

Worm

Later saw a complete use of XML to define a button method, reliable, although the change seems to be a bit monotonous, but can not use the picture is good after all, the first record of the method, have time to try ~


<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "true" >
<shape>
<gradient android:startcolor= "#0d76e1" android:endcolor= "#0d76e1" android:angle= "270"/>
<stroke android:width= "1dip" android:color= "#f403c9"/>
<corners android:radius= "2DP"/>
<padding android:left= "10DP" android:top= "10DP"
android:right= "10DP" android:bottom= "10DP"/>
</shape>
</item>

<item android:state_focused= "true" >
<shape>
<gradient android:startcolor= "#ffc2b7" android:endcolor= "#ffc2b7" android:angle= "270"/>
<stroke android:width= "1dip" android:color= "#f403c9"/>
<corners android:radius= "2DP"/>
<padding android:left= "10DP" android:top= "10DP"
android:right= "10DP" android:bottom= "10DP"/>
</shape>
</item>

<item>
<shape>
<gradient android:startcolor= "#000000" android:endcolor= "#ffffff" android:angle= "180"/>
<stroke android:width= "1dip" android:color= "#f403c9"/>
<corners android:radius= "5dip"/>
<padding android:left= "10DP" android:top= "10DP"
android:right= "10DP" android:bottom= "10DP"/>
</shape>
</item>
</selector>

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.