I am trying to obtain a handle on one of the views in the Action Bar. I have tried calling:
findViewById(R.id.menu_item)
but this returns null unless I call it in the onOptionsItemSelected method. I have also tried calling it from a different object:
findViewById(android.R.id.content).findViewById(R.id.menu_item)
but this has not worked. How can I do this?
(I am not using the ActionBarSherlock library, by the way. Also, this is not a custom ActionView.)
This question is related to
java
android
android-actionbar
I am trying to obtain a handle on one of the views in the Action Bar
I will assume that you mean something established via android:actionLayout
in your <item>
element of your <menu>
resource.
I have tried calling findViewById(R.id.menu_item)
To retrieve the View
associated with your android:actionLayout
, call findItem()
on the Menu
to retrieve the MenuItem
, then call getActionView()
on the MenuItem
. This can be done any time after you have inflated the menu resource.
Source: Stackoverflow.com