2017-02-20 6 views
5

私のアプリケーションにBottom Bar Navigationバーを統合しました。しかし、私がスワイプすると、タブの色は変わらない。私はセレクタファイルを持っているので変です。どのようなアイデアはこの問題を解決するには?BottomNavigationBar - タブアイコンの色を変更します。

Activity.java

BottomNavigationView bottomNavigationView = (BottomNavigationView) 
      findViewById(R.id.bottom_navigation); 


    bottomNavigationView.setOnNavigationItemSelectedListener(
      new BottomNavigationView.OnNavigationItemSelectedListener() { 
       @Override 
       public boolean onNavigationItemSelected(@NonNull MenuItem item) { 
        switch (item.getItemId()) { 
         case R.id.bb_menu_arac: 
          fragment = new AraclarimFragment(); 
          break; 
         case R.id.bb_menu_yaklasan: 
          fragment = new YaklasanlarFragment(); 
          break; 
         case R.id.bb_menu_yakin: 
          fragment = new Yakinimdakiler(); 
          break; 

        } 
        final FragmentTransaction transaction = fragmentManager.beginTransaction(); 
        transaction.replace(R.id.main_container, fragment).commit(); 
        return true; 
       } 


      }); 

selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:color="@color/beyaz" android:state_enabled="true" /> 
<item android:color="@color/colorPrimaryDark" android:state_enabled="false" /> 
</selector> 

activiy.xml

あなたが設定する必要が
<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottom_navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    app:itemBackground="@color/colorPrimary" 
    app:itemIconTint="@color/beyaz" 
    app:itemTextColor="@color/beyaz" 
    app:menu="@menu/bottombar_menu" /> 
+0

ここでselector.xmlを使用しましたか? –

+0

あなたは** android:state_enabled **の代わりに** android:state_enabled **のコードを書いていますか?それが問題になっていますか? – Queendevelopers

+0

コース番号、私はそれを偶然書きました。今更新されました。 @Queendevelopers –

答えて

6

の変更のようなものはまた、これにごselector.xmlを変更します。

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_checked="true" android:color="@color/beyaz" /> 
<item android:color="@color/colorPrimaryDark" /> 
</selector> 
+0

ありがとうございました。 –

+0

先生は必要ありません。ようこそ –

+0

うん、習慣:)) –

0

セレクタをBottomNavigationViewのitemIconTintとして設定します。 app:itemIconTint="@drawable/selector"

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottom_navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    app:itemBackground="@color/colorPrimary" 
    app:itemIconTint="@drawable/selector" 
    app:itemTextColor="@color/beyaz" 
    app:menu="@menu/bottombar_menu" /> 
+0

ありがとうございます。しかし、selector.xmlをちょっと変えなければなりません。再度、感謝します。 –

0

あなたのBottomNavigationViewアンドロイドでこれを追加する必要があります。テーマ= "@スタイル/ Base.ThemeOverlay。 AppCompat.Dark.ActionBar "アイコンの色を変更するのに役立ちます

関連する問題