2016-11-29 1 views
2

Ich verwende Bottom NavigationView und möchte Elemente programmgesteuert ändern. Es gibt 5 Gegenstände und wenn ich den 4. Gegenstand gewählt habe, bleibt Erster Gegenstand immer noch aktiv.Bottom NavigationView Elemente programmgesteuert ändern

<android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottom_navigation" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     app:itemBackground="@color/color_white" 
     app:itemIconTint="@color/drawer_item" 
     app:itemTextColor="@color/drawer_item" 
     android:layout_gravity="start" 
     app:menu="@menu/nav_bar_menu"/> 
+0

verwenden können, können Sie Überprüfen Sie meine Antwort hier http://stackoverflow.com/questions/40202294/set-selected-item-in-android-bottomnavigationview/40721016#40721016, ich glaube, es ist sehr ähnlich zu Ihrem Profi bluten. – Viacheslav

+0

Danke @Viacheslav fand den Hack hier http://stackoverflow.com/questions/40236786/set-initiitially-selected-item-index-id-in-bottomnavigationview –

Antwort

3

Von API 25.3.0 gefunden, Sie setSelectedItemId

BottomNavigationView bottomNavigationView; 
bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation); 
bottomNavigationView.setSelectedItemId(R.id.item_4th); 
Verwandte Themen