如何在TabHost.TabSpec指标中设置自定义视图,仍然显示底部条带

时间:2016-10-04 12:15:35

标签: android android-tabhost android-tabs

我正在使用TabHost和ViewPager来显示标签。对于每个选项卡,我想显示自定义视图作为其指标。 我知道我可以使用TabSpec.setIndicator

来做到这一点
    TabHost.TabSpec spec    =   mTabHost.newTabSpec("tab1");
    spec.setIndicator(createTabView(R.drawable.tab1, "name_of_tab1"));

//Below method returns a view to be set as the indicator of the tab
    private View createTabView(final int id, String tab_name) {
        View view = LayoutInflater.from(this).inflate(R.layout.tabs_icon, null);
        ImageView imageView =   (ImageView) view.findViewById(R.id.tab_icon);
        imageView.setImageDrawable(getResources().getDrawable(id));
        TextView tabName = (TextView) view.findViewById(R.id.tab_name);
        tabName.setText(tab_name);
        return view;
    }

但是在我设置之后,底部标签条(通常是蓝色标签条)消失。我想设置自定义视图,但我还想显示标签条以突出显示当前选择的标签。 请帮助我如何实现这一点。我不想使用PageStrip,因为它在API级别21或更高级别中可用。但我的应用程序支持API级别为16或更高的设备。

0 个答案:

没有答案