B
B
bvitaliyg2013-05-21 21:13:58
Android
bvitaliyg, 2013-05-21 21:13:58

How to read attributes set in menu markup in ActionView?

The situation is quite trivial. The project uses ActionBarSherlock.
There is an XML file with menu markup for the bar:

<item
    android:id="@+id/id"
    android:actionViewClass="com.my.package.CustomView"
    android:icon="@drawable/icon"
    android:showAsAction="always"
    android:title="@string/title"/>

As you can see, the customView class is used as markup for the menu item.
The problem is that you have to set the parameters specified in XML manually in Java code through the methods of the CustomView itself, duplicating what is written in XML:
CustomView v = ((CustomView) menu.findItem(R.id.refresh).getActionView());
v.setTitle(R.string.title);
v.setIcon(R.drawable.icon);
// ...

Is there a way to read the markup from the CustomView itself - on initialization, for example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serso, 2013-05-21
@serso

Use android.view.MenuItem methods: getTitle(), getIcon(),…

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question