Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand navigation list in action bar?

In android you could set a navigation list in action bar by passing spinner adapter and OnNavigationListener. the issue is that the navigation list dont fill most of the action bar, how to make it expand like the gmail app : Example of Gmail app :

enter image description here

My app:

enter image description here

And here's the code :

//... setting the array adapter
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
NavigationListener navigationListener = new NavigationListener();
ListAdapter listAdapter = new ListAdapter();
actionBar.setListNavigationCallbacks(listAdapter, navigationListener);
actionBar.setDisplayShowTitleEnabled(false);

Other problem i face is the size of the spinner item, they show up really small, is that because i dont pass customized textview (look at screenshot)? example of what i do :

private class ListAdapter extends BaseAdapter implements SpinnerAdapter {

    public View getView(int pos, View view, ViewGroup viewGroup) {
        TextView text = new TextView(context);
        text.setText(arrayAdapter.getItem(pos).toString());
        return text;
    }

}
like image 474
Jimmy Avatar asked Jan 22 '12 23:01

Jimmy


1 Answers

You want to implement the getDropDownView method too. This lets you supply a different view for the dropdown list with the metrics and formatting you want.

Consider inflating the framework layouts android.R.layout.simple_spinner_item and android.R.layout.simple_spinner_dropdown_item for these situations. Use findViewById(android.R.id.text1) to get the TextView you should fill out in each one.

like image 179
adamp Avatar answered Oct 21 '22 18:10

adamp