W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
編寫: spencer198711 - 原文:http://developer.android.com/training/backward-compatible-ui/older-implementation.html
這一課討論了如何創(chuàng)建一個(gè)支持舊的設(shè)備并且與新的APIs接口相同的實(shí)現(xiàn)。
在以向后兼容的方式使用較新的UI功能的時(shí)候,最具挑戰(zhàn)的任務(wù)是為舊的平臺版本決定一個(gè)解決方案。在很多情況下,使用舊的UI框架中的功能是有可能完成這些新的UI組件的。例如:
為了往老的設(shè)備上向后移植UI組件,這些一般不是一刀切的解決方案。注意用戶體驗(yàn):在老的設(shè)備上,用戶可能不熟悉新的界面設(shè)計(jì)模式和UI組件,思考一下如何使用熟悉的控件去實(shí)現(xiàn)相同的功能。在很多種情況下,這些通常不會被注意到,特別是在如果新的UI組件在應(yīng)用程序的生態(tài)系統(tǒng)中是突出的(比如Action Bar),或者交互模型是非常簡單和直觀的(比如使用ViewPager去滑動界面)。
你可以使用TabWidget和TabHost(盡管其中一個(gè)也可以使用水平方向的Button控件)去創(chuàng)建Action Bar Tabs的老的實(shí)現(xiàn)??梢栽赥abHelperEclair和CompatTabEclair的類中去實(shí)現(xiàn),因?yàn)檫@些實(shí)現(xiàn)使用了不遲于Android 2.0(Eclair)的APIs。
CompatTabEclair
在實(shí)例變量中保存了諸如tab文本和tab圖標(biāo)等tab屬性,因?yàn)樵诶系陌姹局袥]有ActionBar.Tab對象去處理這些數(shù)據(jù)存儲。
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.)
}
TabHelperEclair
利用了TabHost控件的方法去創(chuàng)建TabHost.TabSpec對象和tab的頁面指示效果:
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.
}
現(xiàn)在你已經(jīng)有了兩種CompatTab
和TabHelper
的實(shí)現(xiàn),一種是使用了新的APIs為了能夠在Android 3.0或其后版本設(shè)備上能夠運(yùn)行,另一種則是使用了舊的APIs為了在Android 2.0或之前的設(shè)備上能夠運(yùn)行。下一課討論在應(yīng)用中使用這兩種實(shí)現(xiàn)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: