gpt4 book ai didi

android - 旧 API 中 TabWidget 的 tabStripEnabled

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:28 24 4
gpt4 key购买 nike

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/3164325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com