Android Compatibility Introduction SetBackground

Source: Internet
Author: User
Tags deprecated

Brief introduction

I believe everyone has used various layouts, and for various layouts will be used to set the background image this function

Android phones are mostly on the market at 4.4.4 or above, but older phones still exist.

So for Android compatibility issues, we still have to take care of.

Treatment Scenarios

How do we deal with Android compatibility issues?

根本:就是对sdk版本所缺少的类或者方法做出相应处理即可
Case analysis

Example one: SetBackground

相信大家都或多或少的使用过,如:LinearLayout.setBackgroud(Drawable background) 但是有没有发现问题?
/** * Set the background to a given drawable, or remove the background. If the * background has padding, this View ' s padding are set to the background ' s * padding. However, when a background was removed, this View ' s padding isn ' t * touched.     If setting the padding is desired, please use * {@link #setPadding (int, int, int, int)}.     * * @param background The drawable to use as the background, or null to remove the * background */     Public void SetBackground(drawable background) {//noinspection DeprecationSetbackgrounddrawable (background); }/** * @deprecated Use {@link #setBackground (drawable)} instead */    @Deprecated     Public void setbackgrounddrawable(drawable background) {

@Deprecated found that the call to Setbackgrounddrawable is actually out of date, it is not recommended to use this method

Use Android Studio's windows+f2 to see the following information

This means that this method is only possible after API 16.

That's the way Android 4.1 Jelly beans (API level 16)

If the phone before this, call this method, there will be a nosuchmethoderror error

So if you use this method to do compatible processing, of course, you can also use the Setbackgroundresource method instead of

This method starts with API 1, so don't worry about it.

For example two: Android 6.0 Delete HttpClient related class resolution also to be resolved etc. ....

解决方案:[http://blog.csdn.net/yangqingqo/article/details/48214865](http://blog.csdn.net/yangqingqo/article/details/48214865)

The above is setbackground compatibility problem, solve, of course, there are many other problems, for the time being not an example, met, in leaf out can be directly resolved, thanks.

Android Compatibility Introduction SetBackground

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.