roughike / BottomBar

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Apache License 2.0
8.42k stars 1.5k forks source link

I can't load a fragment with the setOnTabselectedListner #681

Open Xy-joe opened 7 years ago

Xy-joe commented 7 years ago

I have about 5 different icons(tabs) on my bottom bar. On clicking, they only change colors which i decleared in the xml file but when i try to load a fragment on the different icon(tabs), nothing works. Why is this ? Besides her's my code XML ` <com.roughike.bottombar.BottomBar android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" app:bb_tabXmlResource="@xml/xml" app:bb_activeTabColor="@color/colorAccent" app:bb_inActiveTabAlpha="0.6"

    />`

and here's the xmlresours for the tab `

<tab
    android:id="@+id/home_tab"
    android:title="Home"
    android:icon="@drawable/ic_home"
    barColorWhenSelected="@color/white"
    />
<tab
    android:id="@+id/promo_tab"
    android:title="Promotions"
    android:icon="@drawable/ic_promotions"
    barColorWhenSelected="@color/white"
    />
<tab
    android:id="@+id/chart_tab"
    android:title="Carts"
    android:icon="@drawable/ic_carts"
    barColorWhenSelected="@color/white"
    />
<tab
    android:id="@+id/news_tab"
    android:title="News"
    android:icon="@drawable/ic_news"
    barColorWhenSelected="@color/white"
    />
<tab
    android:id="@+id/settings_tab"
    android:title="@string/action_settings"
    android:icon="@drawable/ic_settings"
    barColorWhenSelected="@color/white"
    />

`

My Activity for implementing this is this

` protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); setToolbar(); mbottombar = (BottomBar) findViewById(R.id.bottomBar); mbottombar.onSaveInstanceState();

    mbottombar.setOnTabSelectListener(new OnTabSelectListener() {
        @Override
        public void onTabSelected(@IdRes int tabId) {
            if (tabId == tabs[0]){
                Settings set = new Settings();
                getSupportFragmentManager().beginTransaction().replace(R.id.container, set).commit();
            }
            if (tabId == tabs[1]){
                Home home = new Home();
                getSupportFragmentManager().beginTransaction().replace(R.id.container, home).commit();
            }
        }
    });

}`
malodita commented 7 years ago

Just a question, for the tabs array you're using what value are you using, are you using the resource Id for each or the tab position.

Xy-joe commented 7 years ago

yes I'm. The id correspond to the one in the XML resource file.

On Mar 15, 2017 11:55 AM, "malodita" notifications@github.com wrote:

Just a question, for the tabs array you're using what value are you using, are you using the resource Id for each or the tab position.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roughike/BottomBar/issues/681#issuecomment-286707797, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQJGodvjPqM-6DFkQ-vKWaeGJpg4BDaks5rl8OFgaJpZM4MaDBx .