Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tabStripEnabled for TabWidget in Older API's

Tags:

android

Android 2.2 i.e API Level 8 has tabStripEnabled="true" for TabWidget how to achieve the same in Older versions of Android?

like image 384
amithgc Avatar asked Jul 02 '10 08:07

amithgc


1 Answers

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) {}
}
like image 176
embo Avatar answered Oct 06 '22 06:10

embo