2013-09-27 61 views
0

我想要将列表视图项目的字体更改为marathi,我使用字体更改TextField的字体,任何人都可以告诉我如何使用列表视图项目执行此操作。如何更改列表查看项目字体样式到MARATHI

+0

这已经被回答了很多次...:http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of -textview-in-android http://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android http://stackoverflow.com/questions/3651086/android-using-custom-font http: //stackoverflow.com/questions/16901930/memory-leaks-with-custom-font-for-set-custom-font等等...... – Cehm

回答

2

创建自定义的TextView类这样

public class CustomTextView extends TextView { 

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     init(); 
    } 

    public CustomTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 

    public CustomTextView(Context context) { 
     super(context); 
     init(); 
    } 

    @SuppressWarnings("null") 
    private void init() { 
     if (!isInEditMode()) { 


      // default style 
      Typeface tf = Typeface.createFromAsset(getContext().getAssets(), 
        "helveticaneue_bold.ttf"); 


      setTypeface(tf); 
     } 
    } 

将您的字体样式(Marathi.ttf文件,在这种情况下,我已经使用helveticaneue_bold.ttf)资产的文件夹。

你行,你已经膨胀到ListView控件在

现在,而不是TextView的使用下面

<yourpackagename.CustomTextView 
      android:id="@+id/tv_title" 
      style="@style/buttontext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/company_profile" > 
     </yourpackagename.CustomTextView> 
+0

警告,该方法知道有内存泄漏。您可能只想为每个应用程序加载一次,然后重新使用您刚加载的那个,而不是重新加载它。考虑使用'Application.java'来加载字体,然后将其存储在内存中(hashmap或任何你想要的),并使用单个方法调用来重用它。 – Cehm

+0

plase接受答案,如果它解决了你的目的。 –

+0

先生我创建了这个类文件,但是在哪个文件中我认为要写xml代码 – SHRIRANG

0

您必须实现CustomAdapter或BaseAdapter来实现这一目标。在getview方法膨胀其他xml文件,其中包含文本视图和settypeface它