Reputation:
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:
How I can get this layout and change it?
Upvotes: 3
Views: 1999
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
Reputation:
Fixed with below code :-
Menu menuView = navigationView.getMenu();
MenuItem menuViewItem = menuView.getItem(4);
TextView walletValue = menuViewItem.getActionView().findViewById(R.id.walletValue);
Upvotes: 6