Java 如何从getTypeface()方法获得的字符串中创建字体?

Java 如何从getTypeface()方法获得的字符串中创建字体?,java,android,android-studio,fonts,android-fonts,Java,Android,Android Studio,Fonts,Android Fonts,我想在数据库中存储字体详细信息,需要时检索字体并将字体应用于TextView userFont = text.getTypeface().toString(); 现在我将userFont存储在我的数据库中,它看起来像“android.graphics”。Typeface@12345543" 我想使用userFont创建一个字体,并将该字体应用于TextView 预期的代码如下所示 TextView txt = findViewById(R.id.showUserEnteredText); Ty

我想在数据库中存储字体详细信息,需要时检索字体并将字体应用于TextView

userFont = text.getTypeface().toString();
现在我将userFont存储在我的数据库中,它看起来像“android.graphics”。Typeface@12345543"

我想使用userFont创建一个字体,并将该字体应用于TextView

预期的代码如下所示

TextView txt = findViewById(R.id.showUserEnteredText);
Typeface font = Typeface.create(userFont);
txt.setTypeface(font);

帮助我应用这样的概念?

字体
不是
字符串
,它的
toString()
只是
对象
实现。以后不能使用该
toString()
输出创建
Typeface
对象。既然你是第一个说要为
TextView
使用什么字体的人,你就不需要调用
getTypeface()
来确定你使用的是什么字体。没有办法将该字符串改回typeface否,对不起。因为是您更改了字体,所以您需要在更改时保存该信息。