Android 2.2即API Level 8擁有tabWidget的tabStripEnabled =「true」 如何在老版本的Android中實現相同?TabStripEnabled for TabWidget in Old API's
回答
private void SetupTabs(TabHost tabHost) {
LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
TabWidget tw = (TabWidget) ll.getChildAt(0);
Field mBottomLeftStrip;
Field mBottomRightStrip;
try {
mBottomLeftStrip = tw.getClass().getDeclaredField("mBottomLeftStrip");
mBottomRightStrip = tw.getClass().getDeclaredField("mBottomRightStrip");
if (!mBottomLeftStrip.isAccessible()) {
mBottomLeftStrip.setAccessible(true);
}
if (!mBottomRightStrip.isAccessible()) {
mBottomRightStrip.setAccessible(true);
}
mBottomLeftStrip.set(tw, getResources().getDrawable(R.drawable.blank));
mBottomRightStrip.set(tw, getResources().getDrawable(R.drawable.blank));// blank is the name of the image in drawable folder
}
catch (java.lang.NoSuchFieldException e) {
// possibly 2.2
try {
Method stripEnabled = tw.getClass().getDeclaredMethod("setStripEnabled", boolean.class);
stripEnabled.invoke(tw, false);
}
catch (Exception e1) {
e1.printStackTrace();
}
}
catch (Exception e) {}
}
非常感謝你!!!! – Eby 2010-10-18 12:05:45
這不適合我。我在2.1和2.2模擬器上都試過。使用這種黑客時還有什麼我應該考慮的? 它正確執行基於當前SDK的代碼,但仍保留TabWidget的底部邊界。 – dannyroa 2010-12-24 05:55:08
這工作完美,有些事情要注意,創建一個透明的圖像,並將其命名爲空白。我通過發表評論做了一些小改動: LinearLayout ll =(LinearLayout)tabHost.getChildAt(0); TabWidget tw =(TabWidget)ll.getChildAt(0); 並替換爲 TabWidget tw = tabHost.getTabWidget(); – Fred 2011-11-09 14:51:58
我做了這麼:
try {
Method setStripEnabled = tabWidget.getClass().getDeclaredMethod(
"setStripEnabled", boolean.class);
setStripEnabled.invoke(tabWidget, true);
Method setLeftStripDrawable = tabWidget.getClass()
.getDeclaredMethod("setLeftStripDrawable", int.class);
setLeftStripDrawable.invoke(tabWidget, R.drawable.tab_line);
Method setRightStripDrawable = tabWidget.getClass()
.getDeclaredMethod("setRightStripDrawable", int.class);
setRightStripDrawable.invoke(tabWidget, R.drawable.tab_line);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
- 1. Old School Sound Programming in Python
- 2. AS3 - for(... in ...)vs for each(... in ...)
- 3. for(var propertyName in object)vs for(propertyName in object)?
- 4. MySQL IN for strings
- 5. 「for each」loop in
- 6. Ignorecase for In Criterion
- 7. For loop in views
- 8. ST_asGeoJson for Multilinestring in php for leaflet
- 9. TabWidget
- 10. Google App for bussines + OpenId + GoogleAPI in Java GAE
- 11. TTL for mongoid in rails
- 12. Set in enum for C#
- 13. ImageTemplateId for OSReload in SL
- 14. fnmatch for windows in C?
- 15. Java.Lang.Throwable in Mono for Android
- 16. SuggestBox for TextArea in gwt
- 17. In App for iOS(Appcelerator)
- 18. In App Purchase for iPhone
- 19. 「for」vs「each」in Ruby
- 20. SIOCGIFHWADDR for ioctlsocket in mingw
- 21. For Loop in Vacuum cleaner
- 22. allowedContentTypes in fluidcontent for fluid_styled_content
- 23. NSTimer in for循環
- 24. Lambda Expression for「not in」?
- 25. AsyncTask in Mono for Android
- 26. 「*」vs「:」in R for model
- 27. 」for「loop in velocity template
- 28. lookbehind in for循環
- 29. Fly In Animation for GridView
- 30. for-in和in中的代碼
我在屏幕底部的標籤, 所以我做了如下...... 我把機器人:layout_marginBottom = 「 - 10dip」 移動bottomStrip關閉屏幕 但想知道確切的方式來做到這一點... 感謝 –
amithgc
2010-07-02 11:46:50