문제

How can I style ActionBar Drop-down Navigation spinner in my custom layout?

Also, how can I change the size of a spinner?

I'm inflating custom layouts in getView() method of my custom adapter:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.list_item_navigation_dropdown, null);
    }

    txtTitle = (TextView) convertView.findViewById(R.id.title);
    txtTitle.setText(spinnerNavItem.get(position).getTitle());
    return convertView;
}

I was trying to change layout size in list_item_navigation_dropdown.xml but it only affects the text value of a spinner.

도움이 되었습니까?

해결책

How can I style ActionBar Drop-down Navigation spinner in my custom layout?

The only part of the Spinner you can theme is the background by applying your own style using the actionDropDownStyle attribute. Here's an example:

<style name="Your.Theme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionDropDownStyle">@style/Your.Spinner</item>
</style>

<style name="Your.Spinner" parent="@android:style/Widget.Holo.Light.Spinner">
    <item name="android:background">@drawable/your_background</item>
</style>

Also, how can I change the size of a spinner?

I think you're asking how to change the layout params of the Spinner, in which case you can't.

The Spinner in the ActionBar is created internally using the ScrollingTabContainerView. By default the width is set to LinearLayout.LayoutParams.WRAP_CONTENT and the height is set to LinearLayout.LayoutParams.MATCH_PARENT. But nothing in the ActionBar API allows you to modify the size of the Spinner.

An alternative is to use ActionBar.setCustomView and inflate a layout that contains your own Spinner.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top