【问题标题】:Letter Spacing on EditText is not workingEditText 上的字母间距不起作用
【发布时间】:2019-07-22 07:02:45
【问题描述】:

我想在 EditText 上设置字母间距,但它不起作用。

我尝试像这样创建 EditText:

 <EditText
                android:id="@+id/pin"
                android:layout_width="match_parent"
                android:layout_height="@dimen/input_text_height"
                android:textSize="@dimen/text_size_extra_large"
                local:MvxBind="Text PinCode"
                android:maxLength="6"
                android:layout_marginRight="32dp"
                android:layout_marginLeft="32dp"
                android:layout_marginTop="10dp"
                android:padding="6dp"
                android:gravity="center"
                android:textColor="@drawable/editText_textColorState"
                android:background="@drawable/editText_borderOnFocus"
                android:letterSpacing="10"/>

字母间距属性不起作用。我做错了什么?

【问题讨论】:

  • android api 版本?
  • Android 5.0 - API 21
  • 尝试在物理设备上运行应用
  • 这就是我正在做的。我没有在模拟器上运行应用程序

标签: android


【解决方案1】:

letterSpacing 需要是一个浮点值。试试android:letterSpacing="0.50"

就像@mike 指出的那样,自 V4.0 起,Android Studio 会在预览中呈现字母间距

旧答案

Android Studio 不会在预览中呈现字母间距,因此您必须在设备上手动运行它才能查看更改。

【讨论】:

  • 给未来读者的一点提示:在 Android Studio 4.0.1 及更高版本中,字母间距在预览中实时更新
【解决方案2】:

在官方文档中,他们提到它需要一个浮点值而不是整数。

android:letterSpacing 文本字母间距。

可能是浮点值,例如“1.2”。

android:letterSpacing="1.2"

所以,你的 EditText 应该是这样的

<EditText
    android:id="@+id/pin"
    android:layout_width="match_parent"
    android:layout_height="@dimen/input_text_height"
    android:textSize="@dimen/text_size_extra_large"
    local:MvxBind="Text PinCode"
    android:maxLength="6"
    android:layout_marginRight="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginTop="10dp"
    android:padding="6dp"
    android:gravity="center"
    android:textColor="@drawable/editText_textColorState"
    android:background="@drawable/editText_borderOnFocus"
    android:letterSpacing="10.0"/>

【讨论】:

    【解决方案3】:

    你必须省略单位,只输入值:

    android:letterSpacing="1.2"

    由于某些原因 letterSpacing 在 AS 预览中没有改变。我必须在物理设备上实际运行应用程序才能看到变化

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多