2012-07-28 49 views
1
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 

下面的离心器中的字体是我使用微调如何设置安卓

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 

回答

0

您需使用适配器创建微调的意见适配器。即使适配器创建的视图只是TextView。这样做可让您致电setTypeface()TextView

我看过您的评论,但您需要在AdaptergetView()方法中执行此操作。确保你的Adapter执行SpinnerAdapterSpinnerAdapter有两种返回视图的方法,getView()getDropDownView()

getView()返回用于显示目的的视图,即未显示微调控制器的弹出窗口(未使用正确字体的窗口)。

getDropDownView()返回用于微调器项目列表的视图。

查看参考SpinnerAdapter here

+0

@ Flunn81我只使用自定义适配器。里面,我正在使用Textview。我正在使用字体。我已经提到这个问题。正如你所看到的有两个屏幕截图在第一图像看起来微调字体没有被设置,但是当我打开微调检查图像2我可以看到正确的话。我的问题是如何将字放入微调器时设置字体。 – 2012-07-28 12:37:48

+0

啊,好吧,明白了。我误解了。现在看看它。 – Flynn81 2012-07-28 12:57:13

+0

我用解决方案更新了我的答案。将适配器更改为使用SpinnerAdapter(如果尚未使用),并使用getView()更改造成问题的视图的字体。 getDropDownView()在列表中使用。 – Flynn81 2012-07-28 13:22:23