【问题标题】:How to add badge counter inside tabhost android如何在tabhost android中添加徽章计数器
【发布时间】:2015-07-11 11:57:02
【问题描述】:

我需要在标签中显示通知的数量。我如何在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;

【问题讨论】:

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


    【解决方案1】:

    您可以通过将其上的视图设置为自定义 tabhosts Spec-

     spec = tabHost.newTabSpec("groups");
        View view = LayoutInflater.from(this).inflate(R.layout.tabwidget_tabs, tabHost.getTabWidget(), false);
        spec.setIndicator(view);
    

    【讨论】:

    • R.layout.tabwidget_tabs 中应该有什么?
    • 这是tabItem的布局。
    • 查看视图 = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tab_layout, null); TextView tv_counter = (TextView) view.findViewById(R.id.tab_counter); BadgeView 徽章 = new BadgeView(this, tv_counter);徽章.setText("6");徽章.show();这是我必须在选项卡中显示徽章的代码。如何更新其他班级的徽章?
    猜你喜欢
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多