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

﹥>﹥吖頭↗ 提交于 2019-12-04 14:15:58

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11874734/dynamically-position-right-corner-arrow-of-the-actionbar-spinner-based-on-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!