How to change the control background and shape by Android programming _android

Source: Internet
Author: User

This article illustrates how the Android programming implementation changes the control's background and shape. Share to everyone for your reference, specific as follows:

1. Changing the background

Create an XML file under Res/drawable:

<?xml version= "1.0" encoding= "UTF-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
    //control is pressed against the background 
  <item android:state_pressed=" true "android:drawable=" @drawable/search_bar_ edit_pressed "/>
      //control is selected background 
  <item android:state_selected=" true "android:drawable=" @drawable/ search_bar_edit_pressed "/>
    //control background in general
  <item android:drawable=" @drawable/search_bar_edit_normal " />
</selector>

2. Change Shape

<shape>
    //gradient
  <gradient android:startcolor= "#8600ff"/>
    //stroke
  <stroke android:width= "2DP" android:color= "#000000"/>
    //Fillet
  <corners android:radius= "5DP"/>
    /margin
  <padding android:left= "10DP" android:top= "10DP"
    android:bottom= "10DP" android:right= "10DP"/>
</shape> 

To reference on a layout file:

android:background= "@drawable/"

For more information on Android-related content readers can view the site: "Android Development Primer and Advanced Course", "Android Layout Layout Skills Summary", "Android Database Operating skills summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

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.