user7913931
user7913931

Reputation:

Change the menu actionLayout value?

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?

Upvotes: 3

Views: 1999

Answers (2)

Kreshnik
Kreshnik

Reputation: 2831

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.

Upvotes: 0

user7913931
user7913931

Reputation:

Fixed with below code :-

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

Upvotes: 6

Related Questions