2013-04-24 83 views
9

我想在Arial字体中显示文本。但Arial字体在android系统字体中不可用。我不想在我的应用程序中使用arial ttf文件。有没有其他的方式来使用Arial字体应用文本。Arial字体的Android中的文本

+3

不可以。任何固有的字体都需要'.ttf' /'.otf'。 – 2013-04-24 05:02:18

+0

我可以直接在我的应用程序中使用ttf文件吗?有没有许可问题? – Keerthi 2013-04-24 05:24:05

+5

并非所有字体都可以免费用于商业目的。所以一定要在使用之前进行检查。话虽如此,我通常一直到http://www.fontsquirrel.com/,它拥有大量的免费字体。比对不起更安全。 ;-)至于Arial字体的许可,请查看Wikipedia上的此链接:http://en.wikipedia.org/wiki/Arial#Free_alternatives – 2013-04-24 05:27:30

回答

9

如果字体在android系统中不可用,那么您必须使用字体文件来将该字体应用于您的textView。我可以知道为什么你不愿意使用字体文件来应用它,因为它提供了相同的功能。

使用字体文件使用范例是:

Typeface tfArial = Typeface.createFromAsset(getAssets(), "arial.ttf"); 
TextView tv = null; 
// find the textview id from layout or create dynamically 
tv.setTypeface(tfArial); 

编辑:

你需要把字体文件arial.ttfasset文件夹中。

+0

您必须在您的应用程序中使用Arial字体。 – AndroidEnthusiastic 2013-04-24 06:33:41

4

下载Arial字体和资产创建的文件夹名称以“字体”,并在那里

Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/arial.ttf"); 
TextView tv = (TextView) findViewById(R.id.CustomFontText); 
tv.setTypeface(tf); 
0

保存字体考虑用书法来在你的Android应用程序的任何自定义字体。

您不需要在每个TextView中添加代码来应用字体。只需在应用程序启动时初始化,您就可以开始。

0

创建Java代码中的TextView或XML这样

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@android:id/text1" 
android:layout_width="match_parent" 
android:textSize="15sp" 
android:textColor="@color/tabs_default_color" 
android:gravity="center" 
android:layout_height="match_parent" 
/> 

请务必保持的ID,因为它是在这里,因为这个ID的TabLayout检查,如果您使用自定义的TextView

然后从代码充气此布局并在该文本视图上设置自定义Typeface,并将此自定义视图添加到该选项卡

for (int i = 0; i < tabLayout.getTabCount(); i++) { 
    //noinspection ConstantConditions 
TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null) 
tv.setTypeface(Typeface);  
tabLayout.getTabAt(i).setCustomView(tv); 

} 
相关问题