2016-12-01 65 views
0

我想用蹦极内嵌字体样式在我的Android XML代码如何将蹦极字体样式给android中的textview?

<RelativeLayout 
     android:id="@+id/sound_setting_layout" 
     android:layout_width="500dip" 
     android:layout_height="350dip" 
     android:layout_marginTop="65dip" 
     android:layout_marginLeft="780dip" 
     android:layout_alignParentTop="true" 
     android:padding="10dip" 
     android:gravity="center" 
     android:visibility="gone" 
     android:background="@drawable/volume_layout" 
     > 
<TextView 
    android:layout_width="450dip" 
    android:layout_height="50dip" 
    android:gravity="center_horizontal" 
    android:layout_alignParentTop="true" 
    android:text="Volume Control" 
    android:textStyle="bold" 
    android:textColor="#ffffff" 
    android:textSize="30dip"   
    /> 

我尝试了很多,但在Android中我找不到字体样式蹦极。

回答

1

我们没有默认蹦极字体样式在android系统,所以如果你想用它下载字体蹦极.TTF文件,并在资产创建一个文件夹命名为字体粘贴DOWNLO交锋字体(.ttf)有 在这里,您可以下载蹦极字体:https://djr.com/bungee/ 在你的代码只是这样做

// Font path insted of bungee.ttf replace your .ttf file 
    String fontPath = "fonts/bungee.ttf"; 

    // text view label which you want to apply Bungee font 
    TextView txtGhost = (TextView) findViewById(R.id.androidSample); 

    // here loading Font Face 
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); 

    // Applying font 
    txtGhost.setTypeface(tf); 
1

加载您的字体文件,然后资产文件夹 在活动的onCreate,请使用以下方法

Typeface face = Typeface.createFromAsset(YOUR_ACTIVITY.this.getAssets(),"fonts/YOUR_FONT_FILE_NAME.otf"); 
your_text_view.setTypeface(face); 
+0

它是否适合你,请尝试从接受答案@Mhanddroid – Ak9637

+0

在那里我能得到的字体文件bungee – Mhandroid

+0

哪里可以得到的字体文件取决于你,搜索谷歌,前下载蹦极字体等。字体可以有付费和免费版本,以便搜索根据您的需要 – Ak9637

0

如果你要使用自定义字体贯穿整个应用程序,在多个TextViews例如,它的更好地使用Singleton模式,因为反复重新实例化字体会减慢应用程序的速度。

试试这个类,并用自己的自定义字体替换的字体路径,请确保您有里面的“资产”文件夹中的自定义字体里面的“主”

public class ProximaTypeface { 
    public static ProximaTypeface instance = new ProximaTypeface(); 

    public ProximaTypeface() { 
    } 

    public Typeface regularTypeFace = null; 
    public Typeface semiBoldTypeFace = null; 

    public static ProximaTypeface getInstance() { 
     return instance; 
    } 

    public void getRegularTypeface(Context context, TextView textView) { 
     if (regularTypeFace == null) { 
      regularTypeFace = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/proxima_nova_regular.otf"); 
     } 
     textView.setTypeface(regularTypeFace); 
    } 

    public void getSemiBoldTypeface(Context context, TextView textView) { 
     if (semiBoldTypeFace == null) { 
      semiBoldTypeFace = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/proxima_nova.otf"); 
     } 
     textView.setTypeface(semiBoldTypeFace); 
    } 

} 
在活动

然后:

ProximaTypeface proximaTypeface = new ProximaTypeface(); 

    TextView myTextView = (TextView) findViewById(R.id.textView); 

    proximaTypeface.getRegularTypeface(context,myTextView); 
+0

这种解决方案在Android 5.1下正常行事?因为它使用了反射 – Ak9637

+0

我已经在针对minSdkVersion 17(Android 4.2 Jelly Bean) – Nour

+0

的应用中测试过了,我们可以使用它来设置应用本身的字体吗?Null – Ak9637

相关问题