1

TabHost のインジケーターにカスタム ビューを使用する必要があります。Android API レベル >=4 では問題ありませんが、Android API レベル <4 ではこのメソッドは実装されていません。なにか提案を?

このメソッドを実装することを考えていましたが、残念ながら、すべての属性が非公開で保護されていないため、TabHost クラスは変更できません。

ありがとう。

4

1 に答える 1

2

リフレクションを使用することをお勧めします:

private void setIndecator(TabHost.TabSpec tabSpec, String label) {
    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout tabView = (LinearLayout) vi.inflate(R.layout.tab_view, null);
    ((TextView)tabView.findViewById(R.id.tabCaption)).setText(label);
    try {
        Method m = tabSpec.getClass().getMethod("setIndicator", View.class);
        m.invoke(tabSpec, tabView);
    } catch (Exception e) {
        //in case if platform 1.5 or via other problems indicator cannot be set as view
        //we have to set as just simple label.
        tabSpec.setIndicator(label, getResources().getDrawable(R.layout.tab_selector));
    }
}
于 2010-11-23T14:45:15.130 に答える