本文介绍了在旧的API的tabStripEnabled的TabWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 2.2的即API级别8已经tabStripEnabled =真的TabWidget如何在较早版本的Andr​​oid实现相同的?

解决方案

 私人无效SetupTabs(TabHost tabHost){

    的LinearLayout LL =(的LinearLayout)tabHost.getChildAt(0);
    TabWidget TW =(TabWidget)ll.getChildAt(0);

    现场mBottomLeftStrip;
    现场mBottomRightStrip;

    尝试 {
        mBottomLeftStrip = tw.getClass()getDeclaredField(mBottomLeftStrip);
        mBottomRightStrip = tw.getClass()getDeclaredField(mBottomRightStrip);

        如果(!mBottomLeftStrip.isAccessible()){
            mBottomLeftStrip.setAccessible(真正的);
        }

        如果(!mBottomRightStrip.isAccessible()){
            mBottomRightStrip.setAccessible(真正的);
        }

        mBottomLeftStrip.set(总重量,getResources()getDrawable(R.drawable.blank));
        mBottomRightStrip.set(总重量,getResources()getDrawable(R.drawable.blank)); //空白是在可拉伸文件夹中的图像的名称

    }
    赶上(java.lang.NoSuchFieldException E){
        //可能是2.2
        尝试 {
            方法stripEnabled = tw.getClass()getDeclaredMethod(setStripEnabled,boolean.class)。
            stripEnabled.invoke(TW,假);

        }
        赶上(例外E1){
            e1.printStackTrace();
        }
    }
    赶上(例外五){}
}
 

Android 2.2 i.e API Level 8 has tabStripEnabled="true" for TabWidgethow to achieve the same in Older versions of 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) {}
}

这篇关于在旧的API的tabStripEnabled的TabWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 05:28