【发布时间】:2017-09-05 06:52:31
【问题描述】:
【问题讨论】:
标签: android android-layout bottomnavigationview
【问题讨论】:
标签: android android-layout bottomnavigationview
像这样尝试使用BottomNavigationView 的setSelectedItemId() 方法
BottomNavigationView bottomNavigationView;
bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigationView);
bottomNavigationView.setSelectedItemId(R.id.home_menu);
或像这样使用您的视图寻呼机的viewPager.setCurrentItem();
viewPager.setCurrentItem(2);
【讨论】:
/***Just try to use below code snipet***/
viewPager.setCurrentItem(2);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
home_icon.setImageDrawable(getResources().getDrawable(R.drawable.home_icon_selected_state, getApplicationContext().getTheme()));
}
else
{
home_icon.setImageDrawable(getResources().getDrawable(R.drawable.home_icon_selected_state));
}
【讨论】:
您可以在res/navigation/mobile_navigation.xml 中指定起始目的地。
更改app:startDestination="@+id/navigation_home" 行:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_home">
<fragment
android:id="@+id/navigation_home"
android:name="com.github.bottomchan.ui.home.HomeFragment"
android:label="@string/title_home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/navigation_dashboard"
android:name="com.github.bottomchan.ui.dashboard.DashboardFragment"
android:label="@string/title_dashboard"
tools:layout="@layout/fragment_dashboard" />
</navigation>
【讨论】: