【问题标题】:Bottom Navigation View : Change the default highlighted Tab when the app launches底部导航视图:在应用启动时更改默认突出显示的选项卡
【发布时间】:2017-09-05 06:52:31
【问题描述】:

如上所示,我有这个按钮导航视图,当我启动我的应用程序时,默认情况下我的“类别”选项卡会突出显示,但我希望在启动我的应用程序时让我的“主页”选项卡突出显示,可以有人帮我摆脱它吗?

【问题讨论】:

    标签: android android-layout bottomnavigationview


    【解决方案1】:

    像这样尝试使用BottomNavigationViewsetSelectedItemId() 方法

    BottomNavigationView bottomNavigationView;
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigationView);
    bottomNavigationView.setSelectedItemId(R.id.home_menu);
    

    或像这样使用您的视图寻呼机的viewPager.setCurrentItem();

    viewPager.setCurrentItem(2);
    

    【讨论】:

      【解决方案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));
         }
      

      【讨论】:

        【解决方案3】:

        您可以在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>
        
        

        【讨论】:

          猜你喜欢
          • 2017-04-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-10-02
          • 1970-01-01
          • 2022-10-24
          • 1970-01-01
          相关资源
          最近更新 更多