从Android中的XML文件访问资产文件夹下的字体

发布于 2024-11-25 04:22:22 字数 496 浏览 4 评论 0 原文

我正在尝试进行应用程序范围内的字体更改并创建一个样式文件来执行此操作。在此文件(如下)中,我只想更改 Android 的 TextAppearance 样式的字体值。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="NightRiderFont" parent="@android:style/TextAppearance">
        <item name="android:typeface"> /***help need here***/ </item>
    </style>
</resources>

但是字体位于“assets/fonts/”中。我如何访问此字体,以便我可以使用该样式作为主题来摆脱以编程方式手动更改所有 TextView 的情况。

摘要:如何访问 XML 中的“资产文件夹中的文件”?

I am trying to do a application-wide font change and creating a style file to do so. In this file (below) I just want to change typeface value of TextAppearance style of Android.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="NightRiderFont" parent="@android:style/TextAppearance">
        <item name="android:typeface"> /***help need here***/ </item>
    </style>
</resources>

However font is in "assets/fonts/". How can I access this font, so I can use that style as a theme to get rid of changing all TextViews by hand programatically.

As summary: How can I access 'a file from assets folder' in XML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

我恋#小黄人 2024-12-02 04:22:23

您可以将 .ttf 文件放在字体文件夹中,而不是资产文件夹中。
要在运行 Android 4.1(API 级别 16)及更高版本的设备上使用 XML 功能中的字体支持,请使用支持库 26+。
右键res文件夹,新建-> Android资源目录->选择字体->好的。
将“myfont.ttf”文件放入新创建的字体文件夹中。

在 res/values/styles.xml 上
添加,

<style name="customfontstyle" parent="@android:style/TextAppearance.Small">
<item name="android:fontFamily">@font/myfont</item>
</style>

在布局文件上添加 android:textAppearance="@style/customfontstyle",

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/customfontstyle"/>

参考: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml

Instead of assets folder, you can put the .ttf file on fonts folder.
To use fonts support in XML feature on devices running Android 4.1 (API level 16) and higher, use the Support Library 26+.
Right click res folder, new -> Android resource directory-> select font -> Ok.
put your "myfont.ttf" file in newly created font folder.

On res/values/styles.xml
add,

<style name="customfontstyle" parent="@android:style/TextAppearance.Small">
<item name="android:fontFamily">@font/myfont</item>
</style>

On layout file add android:textAppearance="@style/customfontstyle",

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/customfontstyle"/>

Refer : https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml

知你几分 2024-12-02 04:22:23

//在代码中访问字体文件,

Typeface type = Typeface.createFromAsset(getResources().getAssets(),"fonts/arial.ttf");
textView.setTypeface(type);//assign typeface to textview

//在assets文件夹中->fonts(文件夹名称)->arial.ttf(字体文件名)

//accessing font file in code,

Typeface type = Typeface.createFromAsset(getResources().getAssets(),"fonts/arial.ttf");
textView.setTypeface(type);//assign typeface to textview

//in assets folder->fonts(foldername)->arial.ttf(font file name)

迎风吟唱 2024-12-02 04:22:23

您可以使用此库: https://github.com/InflationX/Calligraphy

您只需添加您想要在布局上使用的字体。
像这样:

<TextView
 fontPath="fonts/verdana.ttf"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>

You can use this library: https://github.com/InflationX/Calligraphy

You only have to add the font you want to use on your layout.
Like this:

<TextView
 fontPath="fonts/verdana.ttf"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
故事和酒 2024-12-02 04:22:23

1.首先我们可以添加assets文件夹>然后你的应用程序中的 font styles.ttfs
2. 在字符串中编写字体的访问代码,如下所示:

<string name="fontregular">OpenSans-Light.ttf</string>
<string name="fontmedium">OpenSans-Regular.ttf</string>

3. 访问一些布局 xml 文件文本视图代码,如下所示:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="@string/fontregular"
    android:textColor="@color/normalfont"
    android:textSize="@dimen/textregular"/>

4. 添加字体大小的尺寸:

<dimen name="textregular">14sp</dimen>
<dimen name="textheader">16sp</dimen>
<dimen name="smalltext">12sp</dimen>
<dimen name="littletext">10sp</dimen>
<dimen name="hightfont">18sp</dimen>

5. 添加颜色中的字体颜色:

<color name="normalfont">#666</color>
<color name="headerfont">#333</color>
<color name="aquablue">#4da8e3</color>
<color name="orange">#e96125</color>

6. 然后应用更改,这很容易处理更改孔应用程序。
快乐编码保持微笑..

1.Fisrt we can add assets folder> in that your font styles.ttfs in your app then
2.write access code for fonts in strings like :

<string name="fontregular">OpenSans-Light.ttf</string>
<string name="fontmedium">OpenSans-Regular.ttf</string>

3.Accessing some layout xml file textview code like this below:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="@string/fontregular"
    android:textColor="@color/normalfont"
    android:textSize="@dimen/textregular"/>

4.Add dimensions for font size :

<dimen name="textregular">14sp</dimen>
<dimen name="textheader">16sp</dimen>
<dimen name="smalltext">12sp</dimen>
<dimen name="littletext">10sp</dimen>
<dimen name="hightfont">18sp</dimen>

5.Add font color in colors :

<color name="normalfont">#666</color>
<color name="headerfont">#333</color>
<color name="aquablue">#4da8e3</color>
<color name="orange">#e96125</color>

6.Then apply changes it is easy process to change hole app.
Happy coding keep smile..

几度春秋 2024-12-02 04:22:23

您可以从资产文件夹到 xml 文件访问字体文件。

android:fontFamily="fonts/roboto_regular.ttf"

fonts 是 asset 文件夹中的子文件夹。

You can access your font file from assets folder to xml file.

android:fontFamily="fonts/roboto_regular.ttf"

fonts is the sub folder in assets folder.

高跟鞋的旋律 2024-12-02 04:22:22

根据我的研究,没有办法将外部字体添加到 xml 文件中。 xml 中只有 3 种默认字体可用,

但您可以使用此代码在 java 中使用。

Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/verdana.ttf");  
textfield.setTypeface(tf,Typeface.BOLD);

更新:

现在我找到了一种方法来实现这一点,方法是创建一个扩展 TextView 的自定义类并在 xml 文件中使用它。

public class TextViewWithFont extends TextView {
    private int defaultDimension = 0;
    private int TYPE_BOLD = 1;
    private int TYPE_ITALIC = 2;
    private int FONT_ARIAL = 1;
    private int FONT_OPEN_SANS = 2;
    private int fontType;
    private int fontName;

    public TextViewWithFont(Context context) {
        super(context);
        init(null, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs, defStyle);
    }
    private void init(AttributeSet attrs, int defStyle) {
        // Load attributes
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.font, defStyle, 0);
        fontName = a.getInt(R.styleable.font_name, defaultDimension);
        fontType = a.getInt(R.styleable.font_type, defaultDimension);
        a.recycle();
        MyApplication application = (MyApplication ) getContext().getApplicationContext();
        if (fontName == FONT_ARIAL) {
            setFontType(application .getArialFont());
        } else if (fontName == FONT_OPEN_SANS) {
            setFontType(application .getOpenSans());
        }
    }
    private void setFontType(Typeface font) {
        if (fontType == TYPE_BOLD) {
            setTypeface(font, Typeface.BOLD);
        } else if (fontType == TYPE_ITALIC) {
            setTypeface(font, Typeface.ITALIC);
        } else {
            setTypeface(font);
        }
    }
}

在 xml 中,

<com.example.customwidgets.TextViewWithFont
        font:name="Arial"
        font:type="bold"
        android:layout_width="wrap_content"
        android:text="Hello world "
        android:padding="5dp"
        android:layout_height="wrap_content"/>

不要忘记在 xml 的根目录中添加架构

xmlns:font="http://schemas.android.com/apk/res-auto"

,并在 values 目录中创建一个 attrs.xml 文件,该文件保存我们的自定义属性:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="font">
        <attr name="type">
        <enum name="bold" value="1"/>
            <enum name="italic" value="2"/>
        </attr>
        <attr name="name">
            <enum name="Arial" value="1"/>
            <enum name="OpenSans" value="2"/>
        </attr>
    </declare-styleable>
</resources>

更新:

使用此自定义视图时发现一些性能问题
listview,那是因为字体对象每次都会创建
视图已加载。我发现的解决方案是在应用程序中初始化字体
通过

类并引用该字体对象

MyApplication application = (MyApplication) getContext().getApplicationContext();

应用程序类引用该字体对象将如下所示

public class MyApplication extends Application {

    private Typeface arialFont, openSans;

    public void onCreate() {
        super.onCreate();

        arialFont = Typeface.createFromAsset(getAssets(), QRUtils.FONT_ARIAL);
        openSans = Typeface.createFromAsset(getAssets(), QRUtils.FONT_OPEN_SANS);
    }

    public Typeface getArialFont() {
        return arialFont;
    }

    public Typeface getOpenSans() {
        return openSans;
    }
}

In my research, there is no way to add external font to the xml file. Only the 3 default font is available in xml

But you can use in java using this code.

Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/verdana.ttf");  
textfield.setTypeface(tf,Typeface.BOLD);

Update:

Now I find a way to do this by creating a custom class extending the TextView and use that in the xml file.

public class TextViewWithFont extends TextView {
    private int defaultDimension = 0;
    private int TYPE_BOLD = 1;
    private int TYPE_ITALIC = 2;
    private int FONT_ARIAL = 1;
    private int FONT_OPEN_SANS = 2;
    private int fontType;
    private int fontName;

    public TextViewWithFont(Context context) {
        super(context);
        init(null, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs, defStyle);
    }
    private void init(AttributeSet attrs, int defStyle) {
        // Load attributes
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.font, defStyle, 0);
        fontName = a.getInt(R.styleable.font_name, defaultDimension);
        fontType = a.getInt(R.styleable.font_type, defaultDimension);
        a.recycle();
        MyApplication application = (MyApplication ) getContext().getApplicationContext();
        if (fontName == FONT_ARIAL) {
            setFontType(application .getArialFont());
        } else if (fontName == FONT_OPEN_SANS) {
            setFontType(application .getOpenSans());
        }
    }
    private void setFontType(Typeface font) {
        if (fontType == TYPE_BOLD) {
            setTypeface(font, Typeface.BOLD);
        } else if (fontType == TYPE_ITALIC) {
            setTypeface(font, Typeface.ITALIC);
        } else {
            setTypeface(font);
        }
    }
}

and in xml

<com.example.customwidgets.TextViewWithFont
        font:name="Arial"
        font:type="bold"
        android:layout_width="wrap_content"
        android:text="Hello world "
        android:padding="5dp"
        android:layout_height="wrap_content"/>

dont forget to add the schema in root of your xml

xmlns:font="http://schemas.android.com/apk/res-auto"

And create an attrs.xml file inside values directory, which is holding our custom attribues:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="font">
        <attr name="type">
        <enum name="bold" value="1"/>
            <enum name="italic" value="2"/>
        </attr>
        <attr name="name">
            <enum name="Arial" value="1"/>
            <enum name="OpenSans" value="2"/>
        </attr>
    </declare-styleable>
</resources>

Update:

Found some performance issue when this custom view is used in
listview, that is because the font Object is creating every time the
view is loaded. Solution I found is to initialize the font in Application
Class and refer that font object by

MyApplication application = (MyApplication) getContext().getApplicationContext();

Application class will look like this

public class MyApplication extends Application {

    private Typeface arialFont, openSans;

    public void onCreate() {
        super.onCreate();

        arialFont = Typeface.createFromAsset(getAssets(), QRUtils.FONT_ARIAL);
        openSans = Typeface.createFromAsset(getAssets(), QRUtils.FONT_OPEN_SANS);
    }

    public Typeface getArialFont() {
        return arialFont;
    }

    public Typeface getOpenSans() {
        return openSans;
    }
}
半岛未凉 2024-12-02 04:22:22

编辑2:

最后,xml支持字体(也通过支持库向后兼容):https://developer.android.com/preview/features/fonts-in-xml.html


编辑:

我现在使用 书法 库。这是自定义字体最简单的方法。

你能做什么:

  • TextView 中的自定义字体
  • TextAppearance 中的自定义
  • 字体 样式中的自定义
  • 字体 主题中的自定义字体
  • FontSpannable 仅将字体应用于文本的一部分

我找到了另一种方法来做到这一点。

您必须使用此 TextView >tutorial

这并不困难,之后您可以使用带有您自己的字体的 TextView

我不知道是否还有人看这个,但我想这可能会有所帮助。

Edit 2:

Finally fonts are supported by xml (also backwards compatible via support library): https://developer.android.com/preview/features/fonts-in-xml.html


Edit:

I now use the Calligraphy library . It is the easiest way for custom fonts.

What can you do:

  • Custom font in a TextView
  • Custom font in TextAppearance
  • Custom font in Styles
  • Custom font in Themes
  • FontSpannable to only apply font to a part of the text

I found another way to do this.

You have to make your own TextView using this tutorial

It is not that difficult and after this you can just use that TextView with your own font.

I don't know if anybody still watches this, but I thought it might help.

叫嚣ゝ 2024-12-02 04:22:22

如果您使用单一字体,请使用此功能。

public static void applyFont(final Context context, final View root, final String fontName) {
        try {
            if (root instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) root;
                for (int i = 0; i < viewGroup.getChildCount(); i++)
                    applyFont(context, viewGroup.getChildAt(i), fontName);
            } else if (root instanceof TextView)
                ((TextView) root).setTypeface(Typeface.createFromAsset(context.getAssets(), fontName));
        } catch (Exception e) {
            Log.e("ProjectName", String.format("Error occured when trying to apply %s font for %s view", fontName, root));
            e.printStackTrace();
        }
    }

Uses this function if you are using single font.

public static void applyFont(final Context context, final View root, final String fontName) {
        try {
            if (root instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) root;
                for (int i = 0; i < viewGroup.getChildCount(); i++)
                    applyFont(context, viewGroup.getChildAt(i), fontName);
            } else if (root instanceof TextView)
                ((TextView) root).setTypeface(Typeface.createFromAsset(context.getAssets(), fontName));
        } catch (Exception e) {
            Log.e("ProjectName", String.format("Error occured when trying to apply %s font for %s view", fontName, root));
            e.printStackTrace();
        }
    }
风透绣罗衣 2024-12-02 04:22:22

Soorya 是对的,但如果您必须在许多 textView 上放置相同的字体,我建议您将该代码放入返回所需 Typeface 的静态方法中。它将减少代码中的行数。或者甚至更好地创建一个扩展 Application 的类并创建一个返回 Typeface 的 GET 方法。该方法可以从应用程序内的任何 Activity 访问(无需使用静态变量或静态方法)。

Soorya is right, but if you have to put the same font on many textViews, I recommend you to put that code inside a static method that return the Typeface wanted. It will reduce lines in your code. Or even better create a class that extends Application and make a GET method that return the Typeface. That method will be reachable from any Activity inside your application (without the need of using static variables or static methods).

多孤肩上扛 2024-12-02 04:22:22

在不需要以编程方式设置自定义字体的帮助下检查一下。

https://stackoverflow.com/a/27588966/4331353

Check this out with the help of this don't need to set custom font programmatically.

https://stackoverflow.com/a/27588966/4331353

合约呢 2024-12-02 04:22:22

字体更改是 Android 中非常基本的功能,每个应用程序都需要它。因此每个人都只想在应用程序中更改一次,以减少我们的开发时间,所以我建议您查看此链接
FountChanger.class

fount change is very basic functionality in android which is mostly needed to each and every application.so every one want to change only once in application that reduce our development time so i would suggest you to see this link
FountChanger.class.

向日葵 2024-12-02 04:22:22

您刚刚进行了公共调用并附加了这样的方法,

public class TextViewFontType {

public Typeface typeface;

public void fontTextView(final TextView textView, final String fonttype) {
    typeface = Typeface.createFromAsset(textView.getContext().getAssets(), fonttype);
    textView.setTypeface(typeface);
}

您可以使用任何方法 TextView 设置字体系列。

public class FontList {

    public static final String gothicbNormal="fonts/gothicb.ttf";
    public static final String gothicbBold="fonts/gothicb.ttf";
}

在您刚刚通过传递两个参数调用任何地方的方法后,进行了 FontList 调用。

You Have just make Public calls And attached Method like this

public class TextViewFontType {

public Typeface typeface;

public void fontTextView(final TextView textView, final String fonttype) {
    typeface = Typeface.createFromAsset(textView.getContext().getAssets(), fonttype);
    textView.setTypeface(typeface);
}

have you use any where method TextView set font-family.

public class FontList {

    public static final String gothicbNormal="fonts/gothicb.ttf";
    public static final String gothicbBold="fonts/gothicb.ttf";
}

made FontList calss after you have just call methods any where with pass two parameter.

恏ㄋ傷疤忘ㄋ疼 2024-12-02 04:22:22

我采用了 droid kids 的答案,并使其适用于任何字体,只需将字体文件名直接键入 XML:

layout.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto" >

    <!-- where font file is at "assets/fonts/arial.ttf" -->
    <com.odbol.widgets.TextViewWithFont
        ...
        custom:fontFilePath="fonts/arial.ttf" />

</RelativeLayout>

Fonts.java

public class Fonts {

    // use Weak so fonts are freed from memory when you stop using them
    private final static Map<String, Typeface> fonts = new WeakHashMap<>(5);

    /***
     * Returns a font at the given path within the assets directory.
     *
     * Caches fonts to save resources.
     *
     * @param context
     * @param fontPath Path to a font file relative to the assets directory, e.g. "fonts/Arial.ttf"
     * @return
     */
    public synchronized static Typeface getFont(Context context, String fontPath) {
        Typeface font = fonts.get(fontPath);

        if (font == null) {
            font = Typeface.createFromAsset(context.getAssets(), fontPath);
            fonts.put(fontPath, font);
        }

        return font;
    }
}

values/attrs .xml

<resources>

    <declare-styleable name="TextViewWithFont">
        <!-- a path to a font, relative to the assets directory -->
        <attr name="fontFilePath" format="string" />

        <attr name="type">
            <enum name="bold" value="1"/>
            <enum name="italic" value="2"/>
        </attr>
    </declare-styleable>
</resources>

TextViewWithFont.java

public class TextViewWithFont extends TextView {
    private int defaultDimension = 0;
    private int TYPE_BOLD = 1;
    private int TYPE_ITALIC = 2;
    private int fontType;
    private int fontName;

    public TextViewWithFont(Context context) {
        super(context);
        init(null, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs, defStyle);
    }
    private void init(AttributeSet attrs, int defStyle) {
        // Load attributes
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.TextViewWithFont, defStyle, 0);
        String fontPath = a.getString(R.styleable.TextViewWithFont_fontFilePath);
        fontType = a.getInt(R.styleable.TextViewWithFont_type, defaultDimension);
        a.recycle();

        if (fontPath != null) {
            setFontType(Fonts.getFont(getContext(), fontPath));
        }
    }
    private void setFontType(Typeface font) {
        if (fontType == TYPE_BOLD) {
            setTypeface(font, Typeface.BOLD);
        } else if (fontType == TYPE_ITALIC) {
            setTypeface(font, Typeface.ITALIC);
        } else {
            setTypeface(font);
        }
    }
}

I took droid kid's answer and made it work with ANY font, just by typing the font filename directly into the XML:

layout.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto" >

    <!-- where font file is at "assets/fonts/arial.ttf" -->
    <com.odbol.widgets.TextViewWithFont
        ...
        custom:fontFilePath="fonts/arial.ttf" />

</RelativeLayout>

Fonts.java

public class Fonts {

    // use Weak so fonts are freed from memory when you stop using them
    private final static Map<String, Typeface> fonts = new WeakHashMap<>(5);

    /***
     * Returns a font at the given path within the assets directory.
     *
     * Caches fonts to save resources.
     *
     * @param context
     * @param fontPath Path to a font file relative to the assets directory, e.g. "fonts/Arial.ttf"
     * @return
     */
    public synchronized static Typeface getFont(Context context, String fontPath) {
        Typeface font = fonts.get(fontPath);

        if (font == null) {
            font = Typeface.createFromAsset(context.getAssets(), fontPath);
            fonts.put(fontPath, font);
        }

        return font;
    }
}

values/attrs.xml

<resources>

    <declare-styleable name="TextViewWithFont">
        <!-- a path to a font, relative to the assets directory -->
        <attr name="fontFilePath" format="string" />

        <attr name="type">
            <enum name="bold" value="1"/>
            <enum name="italic" value="2"/>
        </attr>
    </declare-styleable>
</resources>

TextViewWithFont.java

public class TextViewWithFont extends TextView {
    private int defaultDimension = 0;
    private int TYPE_BOLD = 1;
    private int TYPE_ITALIC = 2;
    private int fontType;
    private int fontName;

    public TextViewWithFont(Context context) {
        super(context);
        init(null, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs, 0);
    }
    public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs, defStyle);
    }
    private void init(AttributeSet attrs, int defStyle) {
        // Load attributes
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.TextViewWithFont, defStyle, 0);
        String fontPath = a.getString(R.styleable.TextViewWithFont_fontFilePath);
        fontType = a.getInt(R.styleable.TextViewWithFont_type, defaultDimension);
        a.recycle();

        if (fontPath != null) {
            setFontType(Fonts.getFont(getContext(), fontPath));
        }
    }
    private void setFontType(Typeface font) {
        if (fontType == TYPE_BOLD) {
            setTypeface(font, Typeface.BOLD);
        } else if (fontType == TYPE_ITALIC) {
            setTypeface(font, Typeface.ITALIC);
        } else {
            setTypeface(font);
        }
    }
}
软糖 2024-12-02 04:22:22

希望您能充分利用:-

TextView text = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");
text.setTypeface(font);

hope use full to you:-

TextView text = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");
text.setTypeface(font);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文