gpt4 book ai didi

android - 更改所选选项卡的图标

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:34 25 4
gpt4 key购买 nike

我按如下方式设置tablayout,

 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。

最佳答案

我正在使用 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) {

}
});

关于android - 更改所选选项卡的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37630765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com