Question

I would like to ask about the actionbar in the gmail app.

In the main activity, there is a spinner in the actionbar (Inbox, Sent, etc.) and there is no title.

I tried that in my app but there is a bigger gap between the app icon and the spinner than it is in gmail app.

I made the title both invisible and empty but still the gap is somehow bigger.

Do I have to make my own view definition for the actionbar to achieve the same effect?

Many thanks, Martin

Was it helpful?

Solution

Thank you all for answers. The answer of matthias lead me to the following solution that worked like a charm:

public class ZeroPaddingArrayAdapter<T> extends ArrayAdapter<T> {

    public InboxTypeAdapter(Context context, int textViewResourceId, T[] objects) {
        super(context, textViewResourceId, objects);
    }

    public static ArrayAdapter<CharSequence> createFromResource(Context context,
                                                                int textArrayResId, int textViewResId) {
        CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
        return new ZeroPaddingArrayAdapter<CharSequence>(context, textViewResId, strings);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        view.setPadding(
                0,
                    view.getPaddingTop(),
                0,
                view.getPaddingBottom()
        );
        return view;
    }

}

For spinners:

getView() - Get the view of the currently selected item. getDropDownView() - Get the views that are displayed when spinner is open.

We only need to reduce the padding in getView().

Just use this adapter instead of the simple ArrayAdapter.

OTHER TIPS

Create a drawable with the correct padding as your action bar icon.

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/logo"
          android:right="10dp"/>

</layer-list>

Then just set is as your icon in the manifest. You should be able to adjust the padding this way.

Reduce the padding of the Spinner, more precisely the padding of the View in the layout that gets inflated in the getView() method of the Adapter. I just tried this in a sample project, it narrows the gap significantly.

add this line spinner.setPadding(0,0,0,0); to hide the down arrow image when drop down is opened.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top