Android 2.2(即API级别8)的TabWidget具有tabStripEnabled =“ true”
如何在旧版Android中实现相同的目标?
最佳答案
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) {}
}
关于android - 旧版API的TabWidget的tabStripEnabled,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4941522/