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 device
Menu button.
-
Action bar tabs can be implemented using a horizontal LinearLayout
containing buttons, or using the
TabWidget
UI element.
-
NumberPicker
and Switch
widgets can be implemented using
Spinner
and ToggleButton
widgets, respectively.
-
ListPopupWindow
and PopupMenu
widgets can be implemented using
PopupWindow
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
and
TabHost
(although one can alternatively use horizontally laid-out
Button
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
ActionBar.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.
分享到:
相关推荐
The code in this book is compatible with the older C99 version as well as the latest C18 and C++17 standards. Special consideration is given to writing robust, reliable, and secure code that is ...
Short-term outcomes in older patients with peritoneal malignancy treated with cytoreductive surgery and IPEC: Experience with 245 patients from a national centre.pdf
including people with disabilities using assistive technology (AT) and older people. It aims to be a useful go-to guide by giving you practical advice. The book explores the new semantics of ...
Creating an AVD for Your Snake Project 61 Creating a Launch Configuration for Your Snake Project 62 Running the Snake Application in the Android Emulator 66 Building Your First Android Application ...
定义了一个父类指针,为了方便对子类的操作(即:该指针指向"谁"时,用这个指针调用的函数就是"谁"的函数,因为子类的函数的名子都一样,函数里的内容不一样,调用不同子类的函数后,计算的结果就不同) switch (man)//4....
WinLicense combines the same protection-level as Themida with the power of advanced license control, offering the most powerful and flexible technology that allows developers to securely distribute ...
(Unfortunately, it looks like Jogl 1.1.1a will not be upward compatible with Jogl 2, so code written for the older version will not automatically work with the new version. However, the changes that ...
Plugin 'Lombok' (version '0.32-EAP') is not compatible with the current version of the IDE, because it requires build 203.* or older but the current build is AI-211.7628.21 这个异常信息是由于Lombok ...
JDK版本与JDBC版本的关系: Many other versions of the JDBC driver are available. This includes development versions, compatibility with older JDKs, and previous versions of the driver.
8.13 Module: jet2sql-Creating a SQL DDL from an Access Database 9. User Interfaces 9.1 Avoiding lambda in Writing Callback Functions 9.2 Creating Menus with Tkinter 9.3 Creating Dialog Boxes...
上外综合英语 Unit The virtues of growing older.pptx
Quickly start creating Visual C# code and projects with Visual Studio 2015 Work with variables, operators, expressions, and methods Control program flow with decision and iteration statements Build ...
web developer, information architect, product manager, usability professional, content publisher, or an entrepreneur new to the mobile web, Mobile Design and Development provides you with the ...
Product Description Universal Data Access Components (UniDAC) is a library of components that provides direct access to most popular ...Bug with creating a database in the Direct Mode on Android is fixed
Apache Spark is currently one of the most popular systems for large-scale data processing, with APIs in multiple programming languages and a wealth of built-in and third-party libraries. Although the ...
Works well with Unity 2017.x and higher and also you can make it work with older Unity versions just ignore the warning before importing the package. Tested on the below Unity versions: - 2018.2, ...
《Principles of Communication System Simulation with Wireless Aplications》书中附带的源代码,虽然可以在网上找到,但是链接不是那么好找。费了一番功夫,找出来给大家共享。 The hands-on, example-rich ...
Chapter 7: Supporting Older Browsers Chapter 8: Audio and Video Chapter 9: Scalable Vector Graphics Chapter 10: Canvas Part IV: Advanced Features Chapter 11: Indexed DB Chapter 12: Geolocation and ...
It is written with Closure Library, enabling you to build browser-independent applications without painful debugging ceremonies, which even have some limited fallback options for older browsers. ...