set view text align at center in spinner in android

Create a adapter for your spinner like this, ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.my_spinner_style,array_of_values) { public View getView(int position, View convertView,ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTextSize(16); return v; } public View getDropDownView(int position, View convertView,ViewGroup parent) { View v = super.getDropDownView(position, convertView,parent); ((TextView) v).setGravity(Gravity.CENTER); return v; } }; Now your … Read more

How to limit the height of Spinner drop down view in Android

You can use Reflection. Spinner spinner = (Spinner) findViewById(R.id.spinner); try { Field popup = Spinner.class.getDeclaredField(“mPopup”); popup.setAccessible(true); // Get private mPopup member variable and try cast to ListPopupWindow android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner); // Set popupWindow height to 500px popupWindow.setHeight(500); } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) { // silently fail… }

How can I fix the Spinner style for Android 4.x placed on top of the Toolbar

I know this is late but I came accross this question when I encountered this problem myself and I found a solution in the BrowseSessionsActivity of the Google I/O 2014 app and adapted it. Layouts toolbar_spinner.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:orientation=”vertical”> <Spinner android:id=”@+id/toolbar_spinner” style=”@style/Widget.MyApp.HeaderBar.Spinner” android:layout_width=”wrap_content” android:layout_height=”match_parent”/> </LinearLayout> toolbar_spinner_item_actionbar.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout … Read more

Spinner: get state or get notified when opens

Another option to watch for those events is to extend the Spinner class and use one of its methods(performClick() which will trigger its dialog/popup) followed by monitoring the focus of the window holding this custom Spinner. This should provide you with the wanted closed event for all the possible finishing possibilities(for either the dialog or … Read more

Change colour of small triangle on spinner in android

The best and easiest solution: spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP); Other solution (Thanks to Simon) if you don’t want change all Spinners: Drawable spinnerDrawable = spinner.getBackground().getConstantState().newDrawable(); spinnerDrawable.setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { spinner.setBackground(spinnerDrawable); }else{ spinner.setBackgroundDrawable(spinnerDrawable); }

How to set dropdown arrow in spinner?

Basically one needs to create a custom background for a spinner. It should be something like this: spinner_background.xml <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <layer-list> <item> <color android:color=”@android:color/white”/> </item> <item> <bitmap android:gravity=”center_vertical|right” android:src=”https://stackoverflow.com/questions/20422802/@drawable/ic_arrow_drop_down_black_24dp”/> </item> </layer-list> </item> </selector> Then create a custom style for your spinner, where you specify the above selector as background: <style name=”Widget.App.Spinner” parent=”@style/Widget.AppCompat.Spinner”> <item name=”overlapAnchor”>true</item> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)