2

I have the following menu xml code:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/action_select_appshare"
    android:showAsAction="always"
    android:title="@string/action_select_appshare"
    android:actionViewClass="android.widget.Spinner" />

</menu>

Because a Spinner seem to require the definition of the android:spinnerMode attribute from the get-go, and there doesn't seem to be a proper way to set it later on after the Spinner object is created. I was wondering if there's a way to specify additional attributes (such as android:spinnerMode in my e.g.) for an android:actionViewClass within the menu XML?

Thanks!

thisbytes
  • 797
  • 1
  • 5
  • 14

2 Answers2

3

Finally found it:

Related links: 1, 2 and 3

  1. Create a new res/layout file. Put the spinner in it, with all the properties you need/want. Note that the Spinner should be the root view.
  2. In your menu file containing the actionClassProvider=spinner, remove actionClassProvider, and replace it with actionLayout="@layout/my_spinner"

All Done

I hope this helps somebody!

Hack5
  • 3,244
  • 17
  • 37
0

well you could solve it in 2 ways: create a custom spinner and put what you want there, or, get the actionView when inflating this menuItem, and then do what you want with it.

android developer
  • 114,585
  • 152
  • 739
  • 1,270