2013-01-21 63 views
-1

我是Android新手。在android listview中,我想以我自己的風格改變字體。請回復。在此先感謝如何在列表視圖中更改字體。Android Listview字體風格

在XML

....

+0

桑托斯,這是一個重複的問題 – VendettaDroid

+0

有一個在此爲您解答http://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android – VendettaDroid

+0

http://stackoverflow.com/questions/2888508/how-to-change-the-font-on-the-textview – VendettaDroid

回答

0
Typeface typeBold = Typeface.createFromAsset(getAssets(),"fonts/helveticabold.ttf"); 
Typeface typeNormal = Typeface.createFromAsset(getAssets(), "fonts/helvetica.ttf"); 

更多信息,請嘗試以下鏈接

example1

example2

0
In android listview i want to change the font in my own style. 

通過這種方式,我想你想改變子視圖中的字體t帽子正在列表中顯示。對於您需要設置TextViewtypefacegetView()裏面如下

首先初始化的字體在適配器的構造函數可能如下

private Typeface typeFace; 
public MyContructor(Context context) 
    { 
     super(context); 
     mInflater = LayoutInflater.from(mContext); 
     typeFace=Typeface.createFromAsset(mContext.getAssets(), "Fonts/GrinchedRegular.ttf")); 
    } 

然後在getView()

@Override 
    public View getView(final int position, View convertView, final ViewGroup parent) 
    { 
     if (convertView == null) 
     { 
      convertView = mInflater.inflate(R.layout.sample, null); 
     } 
     myText = (TextView) convertView.findViewById(R.id.my_text); 
     myText.setTypeface(typeFace); 
     return convertView; 
    } 
0

首先將您的字體文件添加到您的資產文件夾並使用此代碼

Typeface arial = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf"); 
name_txt.setTypeface(arial); 
0

使用自定義列表 -

要切換到不同的內置字體,使用Android:在ArrayAdopter的getView貨品XML

或setTypeface()字樣。

public class CustomeArrayAdopter extends ArrayAdapter<String> { 
int res; 
Typeface tf; 

public CustomeArrayAdopter(Context ctx, int resource, 
    List<String> items) { 

super(ctx, res,items); 
res=resource; 
tf=Typeface.createFromAsset(ctx.getAssets(),"font/Arial.ttf"); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
//Apply new TypeFace here 
TextView item_text=(TextView)findViewById(R.id.listItemtv); 
item_text.setTypeface(tf); 

..... 
} 

_}