Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
来源:互联网 发布:一块红布知乎 编辑:程序博客网 时间:2024/05/12 23:18
Decide on a Substitute Solution
The most challenging task in using newer UI features in a backward-compatible way is deciding on and implementing an older (fallback) solution for older platform versions. In many cases, it's possible to fulfill the purpose of these newer UI components using older UI framework features. For example:
Action bars can be implemented using a horizontal
LinearLayout
containing image buttons, either as custom title bars or as views in your activity layout. Overflow actions can be presented under the deviceMenu button.Action bar tabs can be implemented using a horizontal
LinearLayout
containing buttons, or using theTabWidget
UI element.NumberPicker
andSwitch
widgets can be implemented usingSpinner
andToggleButton
widgets, respectively.ListPopupWindow
andPopupMenu
widgets can be implemented usingPopupWindow
widgets.
There generally isn't a one-size-fits-all solution for backporting newer UI components to older devices. Be mindful of the user experience: on older devices, users may not be familiar with newer design patterns and UI components. Give some thought as to how the same functionality can be delivered using familiar elements. In many cases this is less of a concern—if newer UI components are prominent in the application ecosystem (such as the action bar), or where the interaction model is extremely simple and intuitive (such as swipe views using a ViewPager
). http://blog.csdn.net/sergeycao
Implement Tabs Using Older APIs
To create an older implementation of action bar tabs, you can use a TabWidget
andTabHost
(although one can alternatively use horizontally laid-outButton
widgets). Implement this in classes called TabHelperEclair
and CompatTabEclair
, since this implementation uses APIs introduced no later than Android 2.0 (Eclair).
The CompatTabEclair
implementation stores tab properties such as the tab text and icon in instance variables, since there isn't anActionBar.Tab
object available to handle this storage:
public class CompatTabEclair extends CompatTab { // Store these properties in the instance, // as there is no ActionBar.Tab object. private CharSequence mText; ... public CompatTab setText(int resId) { // Our older implementation simply stores this // information in the object instance. mText = mActivity.getResources().getText(resId); return this; } ... // Do the same for other properties (icon, callback, etc.)}
The TabHelperEclair
implementation makes use of methods on the TabHost
widget for creating TabHost.TabSpec
objects and tab indicators:
public class TabHelperEclair extends TabHelper { private TabHost mTabHost; ... protected void setUp() { if (mTabHost == null) { // Our activity layout for pre-Honeycomb devices // must contain a TabHost. mTabHost = (TabHost) mActivity.findViewById( android.R.id.tabhost); mTabHost.setup(); } } public void addTab(CompatTab tab) { ... TabSpec spec = mTabHost .newTabSpec(tag) .setIndicator(tab.getText()); // And optional icon ... mTabHost.addTab(spec); } // The other important method, newTab() is part of // the base implementation.}
You now have two implementations of CompatTab
and TabHelper
: one that works on devices running Android 3.0 or later and uses new APIs, and another that works on devices running Android 2.0 or later and uses older APIs.
- Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
- 用较早版本的APIs实现抽象类
- Creating Dialup Connections with RAS APIs
- APIs
- Working with APIs
- Abstracting the New APIs 抽象出新的API
- Interacting with Objective-C APIs
- Building RESTful APIs with Tornado
- Creating Maintainable APIs.pdf 英文原版 免费下载
- Android SDK Manage无法下载各个版本的APIs
- How do I build the Android SDK with hidden and internal APIs available?Creating a module library and
- Working with ADO.NET Schema APIs
- Improve Scalability With New Thread Pool APIs
- Improve Scalability With New Thread Pool APIs
- File handling with Windows.Storage APIs
- Using Legacy C APIs with Swift
- Securing REST APIs With Spring Boot
- Building Faster APIs with NodeJs and Redis
- file外部表--有更新版本!
- Proxying to the New APIs 代理新的API
- 设置C#编译环境
- 书后思考:输出三个数中的中间数。从小到大输出三个数
- java实现zip压缩文件/文件夹
- Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
- 不能为虚拟电脑 xxx 打开一个新任务. Failed to load VMMR0.r0 (VERR_SUPLIB_OWNER_NOT_ROOT). 返回 代码:NS_ERROR_FAIL
- iOS 6.x 旋转问题
- Using the Version-Aware Component 使用版本识别组件
- 源程序丢失了一部分,可通过 ILSpy 对 EXE 项目文件反编译
- LocationRecordService-1
- qwt安装和使用(windows和linux)
- 科大讯飞 Mobile Speech Platform
- Oracle UNDO - 自动管理疑问解答