java - Android setPrompt custom font -
i have got spinner set , have spinnermode set dialog. using custom font everywhere in program, , want know how set prompt of spinner use custom font. have looked everywhere on how , have yet find it.
here how have setup spinner far.
arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.my_spinner_style, items) { public view getview(int position, view convertview, viewgroup parent) { view v = super.getview(position, convertview, parent); typeface tf = typeface.createfromasset(getassets(), "fonts/exo-bold.otf"); ((textview) v).settypeface(tf); return v; } public view getdropdownview(int position, view convertview, viewgroup parent) { view v = super.getdropdownview(position, convertview, parent); typeface tf = typeface.createfromasset(getassets(), "fonts/exo-bold.otf"); ((textview)v).settypeface(tf); //v.setbackgroundcolor(color.green); return v; } }; adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); gaschoice.setprompt("trip type"); gaschoice.setadapter(adapter);
you might want style spinner like:
one approach: (that won't work)
<style name="dropdown" parent="android:style/widget.holo.light.spinner.dropdown.actionbar"> <item name="android:typeface">"mytypeface"</item> <--- there no way reference custom typeface </style>
second approach:
package com.example.spinner; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.graphics.typeface; import android.util.attributeset; import android.view.hapticfeedbackconstants; import android.view.view; import android.view.accessibility.accessibilityevent; import android.widget.listadapter; import android.widget.spinner; import android.widget.textview; public class spinnerplus extends spinner implements dialoginterface.onclicklistener{ private listadapter mpromptadapter; private alertdialog mpromptdialog; private onlongclicklistener monlongclicklistener; public spinnerplus(context context, attributeset attrs, int defstyle, int mode) { super(context, attrs, defstyle, mode); // todo auto-generated constructor stub } public spinnerplus(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); // todo auto-generated constructor stub } public spinnerplus(context context, attributeset attrs) { super(context, attrs); // todo auto-generated constructor stub } public spinnerplus(context context, int mode) { super(context, mode); // todo auto-generated constructor stub } public spinnerplus(context context) { super(context); // todo auto-generated constructor stub } public void setpromptadapter(listadapter adapter){ mpromptadapter = adapter; } @override public void setprompt(charsequence prompt) { alertdialog.builder builder = new alertdialog.builder(getcontext()); textview titleview = new textview(getcontext()); settypeface(titleview); builder.setcustomtitle(titleview); builder.setsinglechoiceitems(mpromptadapter, getselecteditemposition(), this); mpromptdialog = builder.create(); } @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub super.setselection(which); mpromptdialog.dismiss(); mpromptdialog = null; } @override public boolean performclick() { if(!performclick1()){ mpromptdialog.show(); return true; } return false; } @override public void setonitemclicklistener(onitemclicklistener l) { super.setonitemclicklistener(l); } @override public void setonlongclicklistener(onlongclicklistener l) { monlongclicklistener = l; super.setonlongclicklistener(l); } private void settypeface(textview t){ typeface tf = typeface.createfromasset(t.getcontext().getassets(), "fonts/exo-bold.otf"); t.settypeface(tf); } private boolean performclick1(){ sendaccessibilityevent(accessibilityevent.type_view_long_clicked); boolean handled = false; if (monlongclicklistener != null) { handled = monlongclicklistener.onlongclick(this); } if (!handled) { handled = showcontextmenu(); } if (handled) { performhapticfeedback(hapticfeedbackconstants.long_press); } return handled; } }
specify needed font in prompt adapter :)
cheers,
Comments
Post a Comment