Bottom up view

I have added a lower navigation view to my XMl activity. I can not set the default item from the menu items. It always sets the first menu item by default. Also, when I click on other menu items, the selected menu item is not highlighted. If I programmatically set item.setChecked (true), the menu item will be highlighted, but the first menu item will also be highlighted. I use

 compile 'com.android.support:design:25.0.1'

Here is the bottom view of navigation

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:itemBackground="@color/white"
    app:itemTextColor="@color/black"
    app:menu="@menu/navigation_menu">
</android.support.design.widget.BottomNavigationView>

Here is the menu

 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/action_wallet"
    android:enabled="true"
    android:icon="@drawable/ic_account_balance_wallet_black_24dp"
    android:title="wallet"
    app:showAsAction="ifRoom"
    />
<item
    android:id="@+id/action_card"
    android:enabled="true"
    android:title="allowance"
    android:icon="@drawable/ic_credit_card_black_24dp"
    app:showAsAction="ifRoom"
    />

<item
    android:id="@+id/action_transaction"
    android:enabled="true"
    android:icon="@drawable/ic_description_black_24dp"
    android:title="transaction"
    app:showAsAction="ifRoom" />

</menu>

Bottom navigation viewHas anyone encountered such a situation? Any suggestions on how to handle this?

Thanks Priya

+5
source share
2 answers

Add selector.xmlto the folder, drawablefor example, myxml

navbar_color.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="highlight color" />
   <item android:color="normal color"  />
</selector>

BottomNavigationView

app:itemIconTint="@drawable/selector"
app:itemTextColor="@drawable/selector"
+7

true OnNavigationItemSelectedListener, . true OnNavigationItemSelectedListener . user2650128 .

+6

Source: https://habr.com/ru/post/1661131/


All Articles