博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
阅读量:4047 次
发布时间:2019-05-24

本文共 3381 字,大约阅读时间需要 11 分钟。

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 containing image buttons, either as custom title bars or as views in your activity layout. Overflow actions can be presented under the device Menu button.

  • Action bar tabs can be implemented using a horizontal containing buttons, or using the UI element.

  • and widgets can be implemented using and widgets, respectively.

  • and widgets can be implemented using 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 ). http://blog.csdn.net/sergeycao

Implement Tabs Using Older APIs

To create an older implementation of action bar tabs, you can use a and (although one can alternatively use horizontally laid-out widgets). Implement this in classes called TabHelperEclair and CompatTabEclair, since this implementation uses APIs introduced no later than Android 2.0 (Eclair).

Figure 1. Class diagram for the Eclair implementation of tabs.

The CompatTabEclair implementation stores tab properties such as the tab text and icon in instance variables, since there isn't an 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 widget for creating 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. 

你可能感兴趣的文章
移植QT
查看>>
如此调用
查看>>
计算机的发展史
查看>>
带WiringPi库的交叉编译如何处理一
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>
Spring事务的七种传播行为
查看>>
ES写入找不到主节点问题排查
查看>>
Java8 HashMap集合解析
查看>>
欢迎使用CSDN-markdown编辑器
查看>>
Android计算器实现源码分析
查看>>
Android系统构架
查看>>
Android 跨应用程序访问窗口知识点总结
查看>>
各种排序算法的分析及java实现
查看>>
SSH框架总结(框架分析+环境搭建+实例源码下载)
查看>>
js弹窗插件
查看>>
自定义 select 下拉框 多选插件
查看>>
js判断数组内是否有重复值
查看>>
js获取url链接携带的参数值
查看>>
gdb 调试core dump
查看>>
gdb debug tips
查看>>