相关疑难解决方法(0)

使用xml在Android TextView中使用自定义字体

我已将自定义字体文件添加到我的assets/fonts文件夹中.如何从我的XML中使用它?

我可以从代码中使用它如下:

TextView text = (TextView) findViewById(R.id.textview03);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
text.setTypeface(tf);
Run Code Online (Sandbox Code Playgroud)

我不能使用android:typeface="/fonts/Molot.otf"属性从XML做到吗?

java xml fonts android android-layout

91
推荐指数
8
解决办法
13万
查看次数

"只能为某些人制作"原生字体"

我有一个应用程序,可以更改某些元素的字体字体.它适用于大多数人,但在尝试更改字体时可能会有0.5%的异常.堆栈跟踪的重要部分是:

Caused by: java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:147)
at android.graphics.Typeface.createFromAsset(Typeface.java:121)
Run Code Online (Sandbox Code Playgroud)

正如我所说,它适用于大多数人,所以我不认为这是字体文件或我的代码的问题.有关如何解决这个问题的任何建议?

编辑:这是我的代码:

Typeface phoneticFont = Typeface.createFromAsset(getAssets(),
                                                 "fonts/CharisSILR.ttf");
TextView tv;
tv = ((TextView) findViewById(R.id.searchPronunciationTitle));
tv.setTypeface(phoneticFont);
Run Code Online (Sandbox Code Playgroud)

fonts android typeface

74
推荐指数
5
解决办法
6万
查看次数

内存泄漏自定义字体设置自定义字体

以下用于设置自定义字体的代码会降低整个应用程序的速度.我如何修改它以避免内存泄漏,提高速度和管理内存?

public class FontTextView extends TextView {
    private static final String TAG = "FontTextView";

    public FontTextView(Context context) {
        super(context);
    }

    public FontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setCustomFont(context, attrs);
    }

    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setCustomFont(context, attrs);
    }

    private void setCustomFont(Context ctx, AttributeSet attrs) {
        TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.FontTextView);
        String customFont = a.getString(R.styleable.FontTextView_customFont);
        setCustomFont(ctx, customFont);
        a.recycle();
    }

    public boolean setCustomFont(Context ctx, String asset) {
        Typeface tf = null;
        try {
        tf = …
Run Code Online (Sandbox Code Playgroud)

android android-emulator android-intent android-layout android-listview

42
推荐指数
1
解决办法
2万
查看次数

在Android中更改EditText的字体?

有没有办法在Android中更改EditText的字体?我希望它匹配我为所有textViews设置的字体.

fonts android typeface android-edittext

27
推荐指数
4
解决办法
4万
查看次数

在app中使用Roboto字体,最低API级别为14

我有一个最低API级别为14的应用程序.我认为所有兼容设备都应该安装Roboto字体作为默认设置吗?如果我将textView字体设置为Roboto或Roboto Light,它似乎默认为普通的sans字体.

有没有办法使用Roboto而不包括Roboto字体作为资产?

android typeface

19
推荐指数
1
解决办法
3万
查看次数

如何在Android中的EditText上设置自定义字体?

我试图在一个自定义字体上实现EditText.有没有人有更好的方法,而不是我现在正在做的事情?

Typeface myFont = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");
edittext.setTypeface(myFont);
Run Code Online (Sandbox Code Playgroud)

因为我有很多EditText...

android android-edittext

5
推荐指数
3
解决办法
1万
查看次数