9 ,? Use to create backward compatibility

Source: Internet
Author: User

? Abstract UI Interface

For many UI interfaces, different Android versions provide different interfaces. For example, Tab uses actionbar in level = 11 (android3.0 honeycomb), but does not have actionbar in earlier Android versions, but can be replaced by the tab control.

In these cases, if you want to develop Android applications that are applicable to all versions, you need to abstract these UI interfaces. Generally, interfaces or abstract classes are used. And use polymorphism to meet the needs of different Android versions.

? Create a tag abstract class

? Abstract actionbar. Tab

 1 public abstract class CompatTab { 2     ... 3     public abstract CompatTab setText(int resId);  4     public abstract CompatTab setIcon(int resId);  5     public abstract CompatTab setTabListener( 6     CompatTabListener callback); 7     public abstract CompatTab setFragment(Fragment fragment); 8     public abstract CharSequence getText(); 9     public abstract Drawable getIcon();10     public abstract CompatTabListener getCallback(); 11     public abstract Fragment getFragment();12 ...13 }

 

? Implement the tag abstract class for earlier versions

 

? Check the current Android version

 

 

 

 

 

 

 

9 ,? Use to create backward compatibility

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.