相关疑难解决方法(0)

如何在android xml中使用自定义字体?

如何使用我的xml资产文件夹中添加的自定义字体?我知道我们可以setTypeface()在java中使用方法,但我们必须在我们使用它的地方执行此操作TextView.那么还有更好的方法吗?

android textview android-layout

25
推荐指数
1
解决办法
6万
查看次数

带支持库的自定义字体无法在真实设备上运行

我在支持库API 26中使用了自定义字体.我使用样式创建了font-family,并在文本视图中添加了样式.我发现字体将在设计期间在预览中设置,但在Android实际设备中不起作用.下面是我的代码,我还附上了截图.提前致谢.

TextView的:

<TextView
    android:id="@+id/card_number_text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="111 5235 5563 8845"
    android:gravity="left"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginTop="8dp"
    style="@style/creditCardText"
    app:layout_constraintTop_toBottomOf="@+id/payableLayout"
    app:layout_constraintLeft_toLeftOf="@+id/payableLayout"
    app:layout_constraintHorizontal_bias="0.0" />
Run Code Online (Sandbox Code Playgroud)

Style.xml:

<style name="creditCardText">
    <item name="android:textSize">@dimen/textSizeLarge</item>
    <item name="android:fontFamily">@font/font_roboto_medium</item>
    <item name="android:textColor">@color/color_card_number</item>
</style>
Run Code Online (Sandbox Code Playgroud)

字体系列:

<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
    android:fontStyle="normal"
    android:fontWeight="400"
    android:font="@font/roboto_medium" />
Run Code Online (Sandbox Code Playgroud)

的build.gradle:

apply plugin: 'com.android.application'
buildscript {
    repositories {
    }
    dependencies {
   }
}

android {
    signingConfigs {
    }
   compileSdkVersion 26
   defaultConfig {
        applicationId "org.saifintex.skypaytrans"
        minSdkVersion 18
        targetSdkVersion 26
        vectorDrawables.useSupportLibrary = true
        versionCode 7
        multiDexEnabled true
        versionName "1.6"
        testInstrumentationRunner 
        "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake …
Run Code Online (Sandbox Code Playgroud)

android font-family

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

无法在我的项目中使用字体: - "错误:错误:文件名必须以.xml结尾"

我正在尝试为我的Android项目添加字体,因此我可以通过XML使用它.不幸的是,我收到此错误消息:

错误:错误:文件名必须以.xml结尾

我遵循官方Android教程的每一步,不知何故发生此错误,我无法解决它.

这是我的错误

android android-fonts android-debug android-design-library

6
推荐指数
1
解决办法
5602
查看次数