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. Dictionary for ... in ... in it?
- 4. for(var propertyName in object)vs for(propertyName in object)?
- 5. Google apis sdk for windows phone store app
- 6. Ignorecase for In Criterion
- 7. For .. in loop?
- 8. For loop in views
- 9. 「for each」loop in
- 10. MySQL IN for strings
- 11. For ... in questions(Python)
- 12. for-each in XSLT for image
- 13. ST_asGeoJson for Multilinestring in php for leaflet
- 14. TabWidget
- 15. Google App for bussines + OpenId + GoogleAPI in Java GAE
- 16. req.url for/in連接
- 17. NoMethodError for gets.chomp in nil:NilClass
- 18. 「*」vs「:」in R for model
- 19. GAE「for each」in template?
- 20. For Loop in Vacuum cleaner
- 21. impl for rusts in rust
- 22. SuggestBox for TextArea in gwt
- 23. Lambda Expression for「not in」?
- 24. TTL for mongoid in rails
- 25. Javascript for loop in map
- 26. SIOCGIFHWADDR for ioctlsocket in mingw
- 27. $ .post in for循環
- 28. NSTimer in for循環
- 29. Set in enum for C#
- 30. model.predictProbabilities()for LogisticRegression in Spark?
我在屏幕底部的標籤, 所以我做了如下...... 我把機器人:layout_marginBottom = 「 - 10dip」 移動bottomStrip關閉屏幕 但想知道確切的方式來做到這一點... 感謝 –
amithgc
2010-07-02 11:46:50