3

I have a navigation drawer and I can change font, color etc.. by accessing the navigationView.getHeaderView(0); and

Menu m = navigationView.getMenu();
MenuItem mi = m.getItem(index);

and then I'm able to play with items in drawer.

But in my case I have a text view that is another layout:

<item
        android:id="@+id/nav_wallet"
        android:icon="@drawable/ic_balnce"
        android:title="@string/my_wallet"
        app:actionLayout="@layout/wallet_value"/>

In my wallet_value layout I have a textView which I need to change its value, here in the image below:

enter image description here

How I can get this layout and change it?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

2 Answers2

6

Fixed with below code :-

 Menu menuView = navigationView.getMenu();
        MenuItem menuViewItem = menuView.getItem(4);
TextView walletValue =  menuViewItem.getActionView().findViewById(R.id.walletValue);
0

A possible solution in Kotlin would be:

val menuViewItem = navigationView.menu.findItem(R.id.nav_wallet)
val txtWalletVal = menuViewItem.actionView.walletValue
txtWalletVal.text = "-150"

I've used findItem() instead of getItem() in order to have more flexibility when adding new menu items.

Kreshnik
  • 2,661
  • 5
  • 31
  • 39
  • Hi I want to set the menu custom layout to the left|start how can I do that?. I want -150 where `My Wallet` is written. – Pemba Tamang Dec 23 '19 at 05:26