? 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