Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Spinner Toolbar style

How do I achieve the material design of spinner in toolbox? I tried the following but my spinner looks like this

enter image description here

<android.support.v7.widget.Toolbar     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="56dp"     android:background="@color/main_color"     app:contentInsetLeft="14dp"     app:contentInsetRight="14dp"     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"     app:theme="@style/ThemeOverlay.AppCompat.ActionBar">      <Spinner         android:id="@+id/spinner_nav"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />  </android.support.v7.widget.Toolbar> 

My minimum sdk is 15.

on my onCreate

ButterKnife.inject(this);      mToolbar.inflateMenu(R.menu.menu_login);     mToolbar.setTitle(R.string.sign_in);     mToolbar.setOnMenuItemClickListener(this);      SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(this,             R.array.options, android.R.layout.simple_spinner_dropdown_item);      mSpinner.setAdapter(spinnerAdapter);     mSpinner.setOnItemSelectedListener(this); 

A menu is a temporary sheet of paper that always overlaps the App Bar, rather than behaving as an extension of the App Bar.

any links would be a great help

UPDATE

I have managed to achieve what I want

enter image description here

I used this

 ButterKnife.inject(this);          mToolbar.setTitle(R.string.sign_in);         setSupportActionBar(mToolbar);          SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),                 R.array.options, android.R.layout.simple_spinner_dropdown_item);          getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);         getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, this); 

and my xml

  <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="56dp"         android:background="@color/app_secondary_color"         app:contentInsetLeft="14dp"         app:contentInsetRight="14dp"         app:popupTheme="@style/ThemeOverlay.AppCompat"         app:theme="@style/ThemeOverlay.AppCompat.ActionBar">      </android.support.v7.widget.Toolbar> 

But How do I make It white and the text color of the menu is blue? also I have this problem. it seems it is too far away? any way to fix this dropdown arrow?

enter image description here

Update 2

Well after spending so much time trying, I have achieve how to make it white and the text color black through this. I have created my custom layout for dropdown style

<?xml version="1.0" encoding="utf-8"?>  <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/text1"     style="?android:attr/spinnerDropDownItemStyle"     android:singleLine="true"     android:layout_width="match_parent"     android:background="@color/background_material_light"     android:textColor="@color/abc_primary_text_material_light"     android:layout_height="48dp"     android:ellipsize="marquee"/> 

then added this code on my oncreate

 spinnerAdapter.setDropDownViewResource(R.layout.custom_simple_spinner_dropdown_item); 

The Only Problem now I encounter is that the press state is not working, it is just a plane white. if you see on the other pop up menu, when you click an item the background color becomes a little bit darker. Also this annoying icon is still too far from the text.

like image 630
Milk Avatar asked Nov 25 '14 03:11

Milk


1 Answers

If u want press state to work, you should add a Drawable selector instead of color as a background. Selector example:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>     <item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>     <item android:drawable="@drawable/numpad_button_bg_normal"></item>  </selector> 
like image 181
Irakli Dadiani Avatar answered Oct 18 '22 08:10

Irakli Dadiani