Android layout Android Studio通过布局编辑器设置fontfamily

Android layout Android Studio通过布局编辑器设置fontfamily,android-layout,android-fonts,Android Layout,Android Fonts,目前,我正在为运行时设置字体 @Override protected void onFinishInflate() { super.onFinishInflate(); Typeface customFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/customFont.otf"); this.customTxtView.setTypeface(customFont); } 但这种字体并没

目前,我正在为运行时设置字体

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    Typeface customFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/customFont.otf");
    this.customTxtView.setTypeface(customFont);
}
但这种字体并没有反映在Android Studio的布局编辑器中。我尝试过使用与我在代码中使用的相同值设置
android:typeface
以及
android:fontfeamily
,但没有效果

是否可以让布局生成器反映自定义字体更改?

根据

在android 4.1/4.2/5.0中,以下内容 字体系列可用:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

结合

android:textStyle="normal|bold|italic"
这14种变体是可能的:

  • 机器人正规
  • 机械斜体
  • 机器人黑体
  • 机器人粗体斜体
  • 机器人灯
  • 机器人轻斜体
  • 机器人瘦
  • 机器人薄斜体
  • 机器人浓缩
  • 机器人浓缩斜体
  • 机器人浓缩黑体
  • Roboto浓缩粗体斜体
  • 机器人培养基
  • 机器人中斜体
注意:还有
robotium thin
typespace


但正如我看到的,您希望使用自定义字体,因此您会发现:

Android不允许您从XML布局设置自定义字体。 相反,您必须将特定字体文件捆绑到应用程序的资产中 文件夹,并以编程方式进行设置。比如:

TextView textView = (TextView) findViewById(<your TextView ID>);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "<file name>");
textView.setTypeface(typeFace);
TextView TextView=(TextView)findViewById();
Typeface=Typeface.createFromAsset(getAssets(),“”);
textView.setTypeface(字体);
请注意,您只能在安装setContentView()之后运行此代码 打电话。另外,Android只支持一些字体,应该 以
.ttf(TrueType)
.otf(OpenType)
格式。即使如此,一些 字体可能不起作用

是一种在Android上绝对有效的字体,您可以使用 这是为了确认在字体文件不可用的情况下代码是否正常工作 由Android支持

请随意说,如果这篇文章对你没有帮助,根据

在android 4.1/4.2/5.0中,以下内容 字体系列可用:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

结合

android:textStyle="normal|bold|italic"
这14种变体是可能的:

  • 机器人正规
  • 机械斜体
  • 机器人黑体
  • 机器人粗体斜体
  • 机器人灯
  • 机器人轻斜体
  • 机器人瘦
  • 机器人薄斜体
  • 机器人浓缩
  • 机器人浓缩斜体
  • 机器人浓缩黑体
  • Roboto浓缩粗体斜体
  • 机器人培养基
  • 机器人中斜体
注意:还有
robotium thin
typespace


但正如我看到的,您希望使用自定义字体,因此您会发现:

Android不允许您从XML布局设置自定义字体。 相反,您必须将特定字体文件捆绑到应用程序的资产中 文件夹,并以编程方式进行设置。比如:

TextView textView = (TextView) findViewById(<your TextView ID>);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "<file name>");
textView.setTypeface(typeFace);
TextView TextView=(TextView)findViewById();
Typeface=Typeface.createFromAsset(getAssets(),“”);
textView.setTypeface(字体);
请注意,您只能在安装setContentView()之后运行此代码 打电话。另外,Android只支持一些字体,应该 以
.ttf(TrueType)
.otf(OpenType)
格式。即使如此,一些 字体可能不起作用

是一种在Android上绝对有效的字体,您可以使用 这是为了确认在字体文件不可用的情况下代码是否正常工作 由Android支持


请随意说,如果这篇文章对你没有帮助,当选择
TextView
时,你应该看到右边的
textpearance
属性。可以选择预定义的文字外观,也可以展开组并仅指定字体族


选择
TextView
时,您应该会看到右侧的
textAppearance
属性。可以选择预定义的文字外观,也可以展开组并仅指定字体族


这只是验证了这还不可能。谢谢。这只是证明这还不可能。谢谢