如何在android中设置微调器内的字体
下面是我正在使用微调器的适配器如何在android中设置微调器内的字体,android,spinner,Android,Spinner,下面是我正在使用微调器的适配器 I want to show the custom font In my Application. I want to show the custom font inside the spinner. For that I have used the custom adapter for creating the spinner. I am getting the output that I want when spinner opens And I am g
I want to show the custom font In my Application. I want to show the custom font inside the spinner. For that I have used the custom adapter for creating the spinner.
I am getting the output that I want when spinner opens And I am getting the custom fonts. But when spinner close that time word is not readable font is not setting.
Image1: Inside the spinner the word is not readable.![enter image description here][1]
Image2: when spinner open the word is readable:
![enter image description here][2]
I have used the
**Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/kalpurush.ttf");**
**textViewlistview.setTypeface(tf);**
But how should I set the font inside the spinner. when settext inside the spinner.
[1]: http://i.stack.imgur.com/i02XA.png
[2]: http://i.stack.imgur.com/Vkydk.png
您需要使用适配器为微调器创建视图。即使适配器创建的视图只是一个
TextView
。这样做可以在TextView
上调用setTypeface()
我阅读了您的评论,但您需要在适配器的getView()
方法中执行此操作。确保您的适配器
实现SpinnerAdapter
SpinnerAdapter
有两个返回视图的方法,getView()
和getDropDownView()
getView()
返回用于显示目的的视图,即当微调器的弹出窗口未显示时(未使用正确字体的弹出窗口)
getDropDownView()
返回微调器项目列表中使用的视图
查看。@Flunn81的参考资料。我仅使用自定义适配器。在里面,我正在使用Textview。我用的是字体。我已经提到了这个问题。正如您在问题中看到的,在第一个图像中有两个屏幕截图:外观微调器字体未设置,但当我打开微调器检查图像2时,我可以正确地看到单词。我的问题是当word放入微调器时如何设置字体。啊,好的,明白了。我误解了。现在就开始研究。我用解决方案更新了我的答案。如果尚未使用SpinnerAdapter,请将适配器更改为使用SpinnerAdapter,并使用getView()更改导致问题的视图的字体。列表中使用了getDropDownView()。请尝试将implements SpinnerAdapter添加到适配器。你需要我回答中的两种方法。对不起,回到这里。在CustomAdapterSpinner override getView()中,可以使用该方法更改TextView的字体。
private class CustomAdapterSpinner extends ArrayAdapter
{
public CustomAdapterSpinner() {
//super(context, android.R.layout.simple_spinner_item, objects);
super(CustomizeFontsAndroid.this, R.layout.simple_spinner1,R.id.textviewSpinner,strarraySpinner);
// TODO Auto-generated constructor stub
tf1=Typeface.createFromAsset(CustomizeFontsAndroid.this.getAssets(), "fonts/kalpurush.ttf");
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textviewSpinner = (TextView)view.findViewById(R.id.textviewSpinner);
textviewSpinner.setTypeface(tf1);
textviewSpinner.setCompoundDrawables(null, null, null, null);
textviewSpinner.setTextSize(16);
textviewSpinner.setText(strarraySpinner[position].toString()+"\n");
//textviewSpinner.setText(R.string.bangla);
return view;
}
}//end of the Spinner Adapter