Counter + Text TabLayout

1

I have a TabLayout with 4 options, the notification option refers to the notifications received via Firebase.

What I need is to add an unread notifications counter. The code for counting unread notifications is already working perfectly. however the counter I would like to add above the "Notifications" tab.

As Print.

ItriedtousetabLayout.getTabAt(0).setIcon(),buttheresultwasnotwhatwasexpected.

Cananyonegiveahelp?

BelowmyMainActivity

publicclassMainActivityextendsAppCompatActivity{privateSharedPreferencessettings;Stringteste="Tabelas";

private ViewPager mViewPager;
private CriaBanco banco;
private TabLayout tabLayout;
private ViewPager viewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   // mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    //mViewPager = (ViewPager) findViewById(R.id.container);
    viewPager = (ViewPager) findViewById(R.id.container);
    createViewPager(viewPager);

    //mViewPager.setAdapter(mSectionsPagerAdapter);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    //tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); // Torna o Tabs em scroll
    //setupTabIcons();
}

private void setupTabIcons() {
    tabLayout.getTabAt(0).setIcon(R.drawable.ic_star_border_black_12dp);

}

private void createViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFrag(new TabEntrada(), "MOINHO");
    adapter.addFrag(new TabTabelas(), "TABELAS");
    adapter.addFrag(new TabEstoque(), "ESTOQUE");
    adapter.addFrag(new TabNotificacao(), "NOTIFICAÇÕES");
    viewPager.setAdapter(adapter);
}




class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFrag(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}

}

So if I use tabLayout.getTabAt().setIcon() the result is print.

Theiconisinthecenter,andpushesthetitledown.

IfpossibleIwouldlikeittolooklikethis:

    
asked by anonymous 09.03.2017 / 18:00

0 answers