If someone else is looking for the solution to this problem here it is,
Here is sample code which is written with the help of link
use following code to create your adapter and join it to ActionBar List Navigation
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
itemArr = getResources().getStringArray(R.array.array_spinner_items);
items = toArrayList(itemArr, null);
navigationAdapter = new CustomAdapter(this, R.layout.navigation_item_layout, items);
actionBar.setListNavigationCallbacks(navigationAdapter, this);
actionBar.setDisplayShowTitleEnabled(false);
Extend BaseAdapter
or ArrayAdapter
and implement SpinnerAdapter
In your adapter override getDropdownView which is responsible for individual item view in dropdown
and override getView which is responsible for the view appearing in the ActionBar
`public class CustomAdapter extends ArrayAdapter implements SpinnerAdapter {
Context context;
int textViewResourceId;
ArrayList<String> arrayList;
public CustomAdapter(Context context, int textViewResourceId, ArrayList<String> arrayList) {
super(context, textViewResourceId, arrayList);
this.context = context;
this.textViewResourceId = textViewResourceId;
this.arrayList = arrayList;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent){
if (convertView == null)
{
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//convertView = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
convertView = vi.inflate(R.layout.navigation_item_layout, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.navigation_item);
textView.setText(arrayList.get(position).toString());//after changing from ArrayList<String> to ArrayList<Object>
if (position == curitem) {
textView.setHeight(0);
}
else{
textView.setHeight(60);
}
return convertView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.navigation_item_layout, null);
}
TextView textview = (TextView) convertView.findViewById(R.id.navigation_item);
textview.setText(itemArr[position].toUpperCase());
textview.setTextColor(Color.RED);
return convertView;
}
}`
Here is the layout file for spinner item navigation_tem_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigation_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="10dp" />