旧版API中TabWidget的tabStripEnabled

对于TabWidget,Android 2.2即API Level 8的tabStripEnabled =“true”如何在老版本的Android中实现相同?

Solutions Collecting From Web of "旧版API中TabWidget的tabStripEnabled"

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) {} } 

我做到了这一点:

 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(); }