简体   繁体   English

如何在Android中将Bungee字体样式赋予textview?

[英]How to give Bungee font style to textview in android?

I want to use Bungee inline font style in my android xml code 我想在我的android xml代码中使用蹦极嵌入式字体样式

  <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"        
    />

I tried a lot but i could not find font style Bungee in android. 我尝试了很多,但是在Android中找不到字体Bungee。

load your font file to assets folder then in your activities onCreate , use the following methods 将字体文件加载到资产文件夹,然后在您的活动onCreate中,使用以下方法

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

We don't have default bungee font style in android so if you wanna use it download bungee font .ttf file and create a folder in assets named fonts and paste your downloaded font (.ttf) there Here you can download Bungee font: https://djr.com/bungee/ In your code just do this 我们在android中没有默认的橡皮筋字体样式,因此,如果您想使用它,请下载橡皮筋.ttf文件,并在名为fonts的 资产中创建一个文件夹,然后将下载的字体(.ttf)粘贴到此处,您可以在此处下载Bungee字体: 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);

If you're going to use custom fonts throughout your whole application, on multiple TextViews for example, it's bettter to use a Singleton pattern because re-instantiating the fonts over and over will slow down your application. 如果要在整个应用程序中使用自定义字体,例如在多个TextView上,最好使用Singleton模式,因为一遍又一遍地重新设置字体会降低应用程序的速度。

Try this class and replace the font path with your own custom fonts, make sure you have your custom fonts inside "assets" folder inside "main" 尝试此类,并用您自己的自定义字体替换字体路径,确保在“ main”中的“ assets”文件夹中包含自定义字体

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);
    }

}

Then in your Activity: 然后在您的活动中:

   ProximaTypeface proximaTypeface = new ProximaTypeface();

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

   proximaTypeface.getRegularTypeface(context,myTextView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中将样式或字体设置为TextView的文本? - How to set style or font to text of a TextView in android? 如何将字体样式添加到 textview android kotlin - How to add font style to textview android kotlin 如何在Android的TextView中使用`Open Sans`字体样式? - How to use `Open Sans` font style for textview in android? 如何在 Android TextView 中将字体样式设置为粗体、斜体和下划线? - How to set the font style to bold, italic and underlined in an Android TextView? 如何在 android 上没有任何 TextView 的字符串上使用自定义字体样式 - how to use custom font style on string without any TextView on android 如何在Android中为TextView提供渐变? - How to give gradient to TextView in android? 如何在 TextView 中动态更改字体样式? - How to change font Style Dynamically in TextView? 如何在Android中将字体设置为textview? - how to set font to textview in android? Android:在添加focusable = true和focusableInTouchMode = true后如何为TextView提供可聚焦的样式? - Android: How to give a TextView a focusable style after adding focusable=true and focusableInTouchMode=true? 如何解析包含HTML标签(如样式,颜色,字体系列,字体大小以及在android中的textview中设置)的数据 - How to parse the data which contains Html tags like style, color,font family, fontsize and set in textview in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM