Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Get Properties from Menu Layout

I understand the proper usage of how to create a menu from a layout file.

My question is: Is it possible to get properties from a menu file without inflating it?

like image 777
Sababado Avatar asked May 16 '26 01:05

Sababado


1 Answers

No, you have to inflate it, to get access to it. For example:

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.my_menu, menu);
    View v = menu.findItem(R.id.item).getActionView(); // Get access to a View associated with example item
    return true;
}
like image 191
Piotr Chojnacki Avatar answered May 18 '26 14:05

Piotr Chojnacki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!