Android Setbackgroundresource and Setbackgrounddrawable and usage

Source: Internet
Author: User
两个方法的效果是一样,只是区别于效率!
Playbtn.setbackgroundresource (R.drawable.pause_selecor);

From the above can be seen from the resource file to get the Pause_selecor object in drawable, if it is a frequently used drawable object, you can make it a member variable to use,

For example: When OnCreate, read the resource file and convert it to drawable object.

Java code:

Pauseselecor =  mycontext.getresources (). getdrawable (R.drawable.pause_selecor);

When you need to change the background, you do not need to go to the resource file to find, but can pass:

Java code:

Pauseselecor. setbackgrounddrawable (OnPause);  

Android Setbackgroundresource and Setbackgrounddrawable and usage

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.