Android - Remove Icon from TabHost/TabWidget

我们两清 提交于 2019-12-12 18:33:22

问题


Is it possible to remove the icon (indicator) and the space between the text and the top of a Tab in a TabHost/TabWidget? I just want to diplay the text, but i can't.

Thanks in advance.


回答1:


Pass a TextView to setIndicator(View v) method with the associated text. If you want extensive styling, i suggest you pass your own "Tab" model as parameter instead.

public class Tab extends LinearLayout {
public Tab(Context c, int drawable, String label) {
    super(c);

    TextView tv = new TextView(c);

    tv.setText(label);
    tv.setTextColor(getResources().getColorStateList(R.color.tab_text_color));
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    tv.setGravity(0x01);

    setOrientation(LinearLayout.VERTICAL);

    if (drawable != 0) {
        ImageView iv = new ImageView(c);
        iv.setImageResource(drawable);
        addView(iv);
    }
    addView(tv);
}

}



来源:https://stackoverflow.com/questions/7152180/android-remove-icon-from-tabhost-tabwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!