Java Tabhost-Android ViewBadger徽章问题

Java Tabhost-Android ViewBadger徽章问题,java,android,Java,Android,在我的应用程序中,我想在一个选项卡上显示徽章。为此,我使用了android-viewbadger.jar文件,在tab-2的“通知”选项卡上设置了我的徽章 我把我的徽章设置成这样 View target = findViewById(R.id.tab2); badge1 = new BadgeView(this, target); badge1.setText("0"); badge1.setBadgePosition(BadgeView.POSITION_BO

在我的应用程序中,我想在一个选项卡上显示徽章。为此,我使用了android-viewbadger.jar文件,在tab-2的“通知”选项卡上设置了我的徽章 我把我的徽章设置成这样

    View target = findViewById(R.id.tab2); 
    badge1 = new BadgeView(this, target);
    badge1.setText("0");
    badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);
    badge1.toggle();
当我设置徽章时,它会像这样显示在右侧

我还尝试更改标签号

View target = findViewById(R.id.tab1);
View target = findViewById(R.id.tab2);
View target = findViewById(R.id.tab3); 
View target = findViewById(R.id.tab4);  
但它总是显示在右边 以下是我正在使用的代码

@Override
protected void onCreate(Bundle arg0) {
    // TODO Auto-generated method stub
    getActionBar().hide();
    super.onCreate(arg0);
    setContentView(R.layout.fr_tabs);
    mainactivity_context = MainActivity.this;

    mtabhost=(TabHost)findViewById(android.R.id.tabhost);

    mtabhost.setup();/// it starts the tabs
    mtabhost.setOnTabChangedListener(this);


    mtabhost.addTab(newTab(TAB_HOME,R.string.Home,R.id.tab1,R.drawable.people_icon_dark));
    mtabhost.addTab(newTab(TAB_INBOX, R.string.Inbox, R.id.tab2, R.drawable.main_profile_icon));        
    mtabhost.addTab(newTab(TAB_Profile, R.string.Profile, R.id.tab3, R.drawable.notification_icon_ark));
    mtabhost.addTab(newTab(TAB_Setting, R.string.Setting, R.id.tab4, R.drawable.messages_icon_dark));
    mtabhost.addTab(newTab(TAB_VIDEOS, R.string.Video, R.id.tab5, R.drawable.more_icon_dark));
}


private TabSpec newTab(String tag, int label_id, int tab_content_id, int res)

{
    // TODO Auto-generated method stub
    View indicator=LayoutInflater.from(this).inflate(R.layout.tab_sample, null,false);

     ((TextView) indicator.findViewById(R.id.tex)).setText(label_id);            
     ((ImageView) indicator.findViewById(R.id.img)).setImageResource(res);

      ///we will use tabspec 
        TabSpec tabSpec=mtabhost.newTabSpec(tag);
        tabSpec.setIndicator(indicator);
        tabSpec.setContent(tab_content_id);

        View target = findViewById(R.id.tab2); 
        badge1 = new BadgeView(this, target);
        badge1.setText("0");
        badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);
        badge1.toggle();

        return tabSpec;
}

@Override
public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub

    if(TAB_HOME.equals(tabId)){
        People Frg=new People();
        Bundle b=new Bundle();
        b.putString("tag", tabId);

        Frg.setArguments(b);

        updateTab(Frg,R.id.tab1,true);
        current_tab=1;
        return;
    }

    if(TAB_INBOX.equals(tabId)){
        Profile Frg=new Profile();
        Bundle b=new Bundle();
        b.putString("tag", tabId);

        Frg.setArguments(b);

        updateTab(Frg,R.id.tab2,true);
        current_tab=1;          
        return;
    }

    if(TAB_VIDEOS.equals(tabId)){
        More Frg=new More();
        Bundle b=new Bundle();
        b.putString("tag", tabId);

        Frg.setArguments(b);

        updateTab(Frg,R.id.tab5,true);
        current_tab=4;
        return;
    }

    if(TAB_Profile.equals(tabId)){
        Intent intent = new  Intent(this, Notifications.class);
        startActivity(intent);
    }       
 }

    private void updateTab(Fragment frg,
        int place_holder, boolean addTobackStack) 
{
    // TODO Auto-generated method stub
    FragmentTransaction ft=getFragmentManager().beginTransaction();

    ft.replace(place_holder, frg);
    if(addTobackStack)
        ft.addToBackStack(null);
        ft.commit();
}


 public void launchNewFragment(Fragment frg1, int containerId) {

     updateTab(frg1, containerId,true);
     }
 public void launchfinishfragment(Fragment frg1, int containerId,boolean b) {         
     updateTab(frg1, containerId,true);
     }
}
选中以启用布局绑定选项 设置=>Developer选项=>Layout-Bound

当我使用公共视图getChildTabViewAt(int索引)时;方法自


可能会对您有所帮助。对于示例应用程序,@VisruthCV表示我只在tab@VisruthCV我已经看过这篇文章,并且像这样设置我的徽章位置“
badge1.setText(“0”);徽章1.立杆位置(徽章视图位置\底部\右侧)
        View target = findViewById(R.id.tab2);
        target = mtabhost.getTabWidget().getChildTabViewAt(2); 

 my output will be this