更改所选标签的图标 [英] Changing the icon of selected tab

查看:87
本文介绍了更改所选标签的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将标签布局设置如下,

Im setting the tablayout as follows,

 private void setupTabIcons() {

        TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
        tabOne.setText("Status");
        tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.status, 0, 0);
        tabLayout.getTabAt(0).setCustomView(tabOne);

        TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
        tabTwo.setText("Rating");
        tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.rateit, 0, 0);
        tabLayout.getTabAt(1).setCustomView(tabTwo);
}

如何更改所选标签的图标?我正在使用tablayout.

How can I be able to change the icon of selected tab? im using tablayout.

推荐答案

我正在使用TabLayout.OnTabSelectedListener:

wptabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            tab.setIcon(R.drawable.newicon);
             //also you can use tab.setCustomView() too
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tab.setIcon(R.drawable.oldicon);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

这篇关于更改所选标签的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆