android - Custom Spinner's context menu -
how customize spinners' context menu? have done customization selector view (http://i.stack.imgur.com/ujzyp.png) have no idea how such content menu.
for example selector different color, rounded corners, bigger font etc.
now looks like: http://i.stack.imgur.com/jnh31.png
fragment's layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:background="@color/white" tools:context="tenkol.design.com.imbrecords.fragmenteditprofile"> ..... <spinner android:id="@+id/spinner_countries" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/edittext_edit_user_email" android:layout_margintop="12dp" android:layout_centerhorizontal="true" android:drawselectorontop="true" android:popupbackground="@color/blue" style="@style/spinner_style" /> ..... </relativelayout>
@style/spinner_style:
<style name="spinner_style"> <item name="android:background">@drawable/spinner_bg</item> <item name="android:layout_marginleft">3dp</item> <item name="android:layout_marginright">3dp</item> <item name="android:layout_marginbottom">10dp</item> <item name="android:paddingleft">8dp</item> <item name="android:paddingtop">5dp</item> <item name="android:paddingbottom">5dp</item> </style>
@drawable/spinner_bg:
<?xml version="1.0" encoding="utf-8"?>
<item> <layer-list> <item> <shape> <gradient android:angle="90" android:endcolor="#ffffff" android:startcolor="#ffffff" android:type="linear" /> <stroke android:width="1dp" android:color="@color/blue" /> <corners android:radius="5dp" /> <padding android:bottom="3dp" android:left="3dp" android:right="10dp" android:top="3dp" /> </shape> </item> <item> <bitmap android:gravity="center_vertical|right" android:src="@drawable/spinner" /> </item> </layer-list> </item>
and have custom adapter spinner:
class spinadapter extends arrayadapter<datacountry>{ private context context; private list<datacountry> values; public spinadapter(context context, int textviewresourceid, list<datacountry> values) { super(context, textviewresourceid, values); this.context = context; this.values = values; } public int getcount(){ return values.size(); } public datacountry getitem(int position){ return values.get(position); } public long getitemid(int position){ return position; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = layoutinflater.from(context); view row = inflater.inflate(r.layout.spinner_layout_row, parent, false); textview countryname = (textview)row.findviewbyid(r.id.spinner_row); countryname.settext(context.getstring(r.string.edit_user_country)); countryname.settextsize(typedvalue.complex_unit_px, context.getresources().getdimension(r.dimen.abc_text_size_title_material_toolbar)); countryname.settextcolor(context.getresources().getcolorstatelist(r.color.deep_blue)); return row; } @override public view getdropdownview(int position, view convertview, viewgroup parent) { textview label = new textview(context); label.settextcolor(color.black); label.settext(values.get(position).getname()); return label; } }
so repeat question: how make custom design spinner? (rounded corners, bigger font, selector, maybe divider between items)
thanks help.
update getdropdownview()
code , create custom layout of spinner item
@override public view getdropdownview(int position, view convertview,viewgroup parent) { view row= view.inflate(mcontext,r.layout.spinner_item_list, null); textview label=(textview)row.findviewbyid(r.id.textview); label.settext(values.get(position).getname()); label.settextsize(typedvalue.complex_unit_px, context.getresources().getdimension(r.dimen.abc_text_size_title_material_toolbar)); label.settextcolor(context.getresources().getcolorstatelist(r.color.deep_blue)); return row; }
Comments
Post a Comment