Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically position right corner arrow of the ActionBar Spinner based on length of displayed title

In the Google+ App, the position of the right corner arrow of the ActionBar Spinner adapts to the length of the current string showing. For example, the Spinner's length seems shorter when Family is picked versus when Acquaintances is picked.

What do I have to do to get the right corner arrow to position dynamically based on the title's length? My guess is that there's an attribute I can set in styles.xml that will do that for me.

Here's my styles.xml:

<style name="MyStyle" parent="android:style/Theme.Holo">
    <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
</style>

<style name="MyDropDownNav" parent="android:style/Widget.Holo.Spinner">
    <item name="android:AttributeHere">AttributeValue</item>
</style>

Here's the code I have in my MainActivity.java:

ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

// Specify a SpinnerAdapter to populate the dropdown list.
SpinnerAdapter dataAdapter = new ArrayAdapter<String>(
        actionBar.getThemedContext(),
        android.R.layout.simple_list_item_1, android.R.id.text1,
        new String[] { "AAAAAAAAAAAAAAA", "BB" });

// Set up the dropdown list navigation in the action bar.
actionBar.setListNavigationCallbacks(dataAdapter, this);

Unlike in Google+, the position of my right corner arrow is always fixed. So if I choose from "AAAAAAAAAAAAAAA" to "BB" from the dropdown, the arrow doesn't move at all.

like image 686
Barney Avatar asked Nov 13 '22 00:11

Barney


1 Answers

Please refer the code of android pure Calendar, in its adapter, getView() always returns the current item in Calendar so that the width of the Spinner is equal to the current item. Actually, the Spinner width in ActionBar is always calculated as the length of its longest item. Calendar does some special process here.

like image 165
user1596883 Avatar answered Dec 10 '22 22:12

user1596883