[英]how to set font to textview in android?
我是這樣做的,但是它逼近了。 我想更改textview font
。
TextView mWeddingDataandTime=(TextView)findViewById(R.id.wedding_weddingtime_txt);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/CURLZ_.otf");
mWeddingDataandTime.setTypeface(face);
我正在使用.otf
文件。 它在資產文件夾中。 任何想法?
嘗試這個:
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
txt.setTypeface(font);
請注意,文件擴展名是“ ttf”,用於在Google中搜索要在此擴展名中下載的任何字體
例如: http : //www.creamundo.com/
在代碼中,您使用fonts/CURLZ_.otf
作為路徑,但是您說字體文件直接位於資源中,因此您的代碼應為
Typeface face=Typeface.createFromAsset(getAssets(),"CURLZ_.otf");
如果資源文件夾中沒有字體文件夾。
我沒有測試它,但是我認為它可以幫助您:
TextView mWeddingDataandTime=(TextView)findViewById(R.id.wedding_weddingtime_txt);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/CURLZ_");
mWeddingDataandTime.setTypeface(face);
更好地利用樣式和主題以及內置字體來解決與性能相關的問題以及與應用相關的問題的大小樣式與主題
如果您的字體僅位於資產文件夾中,而不位於asser / fonts中,則請使用此字體
Typeface face=Typeface.createFromAsset(getAssets(),"CURLZ_.otf");
下面是我在項目中使用過的代碼,它正在運行...您可能需要進行一些更改
Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),"segoeuil.ttf");
TextView loantext = (TextView)findViewById(R.id.loantext);
length1.setTypeface(myTypeface);
1)將字體放在資源文件夾中,而不是字體文件夾中2)在代碼中使用getthis.getAssets()或youractivity.this.getAssets()代替getAssests()
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.