How to create a dropdown in ActionBar in Honeycomb?

I am working on Android Honeycomb with ActionBar. I created an ActionBar as follows:

// Configures the action bar private void configureActionBar() { mActionBar = getActionBar(); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.rooms, android.R.layout.simple_spinner_dropdown_item); ActionBar.OnNavigationListener navigationCallback = new ActionBar.OnNavigationListener() { public boolean onNavigationItemSelected(int itemPosition, long itemId) { String[] rooms = getResources().getStringArray(R.array.rooms); mAppState.setCurrentRoom(rooms[itemPosition]); return false; } }; mActionBar.setListNavigationCallbacks(spinnerAdapter, navigationCallback); } 

The image below shows a screenshot of the ActionBar. I would like to create a drop-down list, but don't know how to do it. This link contains some XML samples, but I don’t know how to apply them and how to style specific elements that are listed below.

ActionBar Dropdown List for Styling

Here is a list of the changes I would like to make:

  • Change the font size of the selected item according to the word type "Room Manager"
  • Deletes the gray line underlying the currently selected item
  • Remove the blue line at the top of the dropdown
  • Add radio buttons to the list items and check the selected item in the drop-down list
  • Change the color of the lines separating list items

Does anyone have any ideas on how to do this?

Thanks!

+4
source share
1 answer

I learned how to style items in a list, as well as a displayed item. The solution included the creation of two layouts of xml files in the / res / layout directory - one for the spinner drop-down elements and one for the selector (the displayed element). Then I was able to add view resources to the ArrayAdapter.

R.layout.spinner_dropdown_text_view:

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinnerDropdownTextView" android:layout_width="match_parent" android:layout_height="50dp" android:paddingLeft="10dp" android:gravity="center_vertical" android:textSize="18dp" /> 

R.layout.spinner_selector_text_view:

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinnerSelectorTextView" android:layout_width="210dp" android:layout_height="match_parent" android:paddingTop="12dp" android:textSize="18dp" android:textColor="@android:color/black" /> 

ArrayAdapter Code:

 ArrayAdapter<CharSequence> aa = ArrayAdapter.createFromResource(this, R.array.rooms, R.layout.spinner_selector_text_view); aa.setDropDownViewResource(R.layout.spinner_dropdown_text_view); 

Result:

The result

Unfortunately, I was not able to figure out how to add switches, or how to remove any horizontal line.

+3
source

Source: https://habr.com/ru/post/1403965/


All Articles