如何在tabhost android中添加徽章计数器

时间:2015-07-11 11:57:03

标签: android android-layout android-fragments android-activity

我需要在标签中显示通知的数量。我如何在android中做到这一点。我的标签代码如下所示。

    mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

    mTabHost.addTab(mTabHost.newTabSpec("HOME").setIndicator("HOME"),
            homepage.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("NOTIFICATIONS").setIndicator("NOTIFICATIONS"),
            notificationfragment.class, null);
    return rootView;

1 个答案:

答案 0 :(得分:0)

您可以通过将其上的视图设置为 -

来自定义tabhosts Spec
 spec = tabHost.newTabSpec("groups");
    View view = LayoutInflater.from(this).inflate(R.layout.tabwidget_tabs, tabHost.getTabWidget(), false);
    spec.setIndicator(view);