Bottombar: Easy way to change icon when tab selected?

Created on 3 Jan 2017  路  7Comments  路  Source: roughike/BottomBar

I've looked through the code and I don't see any method for easily changing the icon when it is selected. Is this a feature you can add, or plan on adding; or, and I just not looking hard enough to see that you already have something like this available.

enhancement

Most helpful comment

I also need to change icon because the needed selected icon is not exactly the same.
I've tried selector drawable.
It works for pressed state, I see my selected icon when I press the button.
But the selected (or checked or active) state is not treated.
Can you set the selected state when a button is activated ?

Thanks.

All 7 comments

I think they will not add a method to change the icon when active or inactive.It can only change the pure color.The google official only supports pure color icon.

I also need to change icon because the needed selected icon is not exactly the same.
I've tried selector drawable.
It works for pressed state, I see my selected icon when I press the button.
But the selected (or checked or active) state is not treated.
Can you set the selected state when a button is activated ?

Thanks.

I found a workaround.
Use selector drawables :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icon_selected" android:state_pressed="true" />
    <item android:drawable="@drawable/icon_selected" android:state_selected="true" />
    <item android:drawable="@drawable/icon_normal"/>
</selector>

and force the selected state :

        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override public void onTabSelected(@IdRes int tabId) {
                for (int i = 0; i < bottomBar.getTabCount(); i++) {
                    BottomBarTab tab = bottomBar.getTabAtPosition(i);
                    tab.findViewById(com.roughike.bottombar.R.id.bb_bottom_bar_icon).setSelected(tab.getId() == tabId);
                }
            }
        });

Nice @Deedee85 ,I will try.

this change is in PR, you will be able to send a state drawable and so whatever you need to do when the tab is in state_selected or not

It's now possible with version 2.2.0 and up, see the README.

This is great! Thanks for adding!

Was this page helpful?
0 / 5 - 0 ratings