【问题标题】:How to make ⌫ symbol backward-compatible in Android Studio?如何使 ⌫ 符号在 Android Studio 中向后兼容?
【发布时间】:2020-06-13 08:31:25
【问题描述】:

退格符号“⌫”显示在运行 Android API 版本 28 的设备上,但未显示在运行 API 版本 15 的模拟器上。我正在使用以下代码。请帮忙

<Button
        android:id="@+id/backspace"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#F5F5F5"
        android:text="\u232b"
        android:textSize="35sp"
        app:layout_column="0"
        app:layout_gravity="fill"
        app:layout_row="0"
        app:layout_rowWeight="1" />

【问题讨论】:

  • 您可以尝试使用 Image 作为图标,然后使用 ImageButton 在所有 API 版本上显示相同。

标签: android android-studio backwards-compatibility


【解决方案1】:

旧的 android 版本似乎没有支持此符号的字体,因此您必须为此按钮使用支持的 font-family 您可以检查支持的字体here 并使用下载的字体,您可以查看 here 以了解如何操作,不要忘记旧 API 的 this 部分,但这里 min api-level 为 16

并像使用它

<Button
    android:id="@+id/backspace"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F5F5F5"
    android:text="\u232b"
    android:fontFamily="@font/myfont" //your downloaded font family name
    android:textSize="35sp"
/>

如果你需要支持 api 15 你可以使用

val typeface = resources.getFont(R.font.myfont)
button.typeface = typeface

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 2017-10-02
    • 2011-02-09
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多