【问题标题】:First letter input in EditText is not fully visible when using a custom font in Android在 Android 中使用自定义字体时,EditText 中的首字母输入不完全可见
【发布时间】:2020-01-22 14:26:41
【问题描述】:

在 Android Studio 中使用带有 EditText 的自定义字体时,我似乎无法正确显示我的第一个字母

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <EditText
        android:id="@+id/editText"
        android:paddingLeft="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:fontFamily="@font/telly_humble"
        android:textSize="35dp"
        android:text="jay" />

</RelativeLayout>

编辑:忘了说我也试过 padding-left 或 start,对我都没有用。

我的最终解决方案是更改字体。

【问题讨论】:

  • 去掉marginLeft后试试。
  • 把 paddingleft 放进去检查一下。
  • 我之前尝试过填充,这就是为什么我也尝试使用 marginLeft 而不是 paddingLeft 他们都没有很好的工作。
  • 这不是最好的解决方案,但您可以简单地在文本前添加一个空格
  • 能否也添加自定义字体 xml 文件?

标签: android android-layout android-edittext


【解决方案1】:

尝试添加 paddingLeft。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <EditText
        android:id="@+id/editText"
        android:layout_marginLeft="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:fontFamily="@font/telly_humble"
        android:paddingLeft="10dp"
        android:textSize="35dp"
        android:text="jay" />

</RelativeLayout>

【讨论】:

  • 对不起,忘了说我已经尝试过填充但仍然不行。
【解决方案2】:

在左侧和右侧添加填充应该可以解决问题

<EditText
    android:paddingLeft="40dp"
    android:paddingRight="40dp"
    android:id="@+id/editText"
    android:layout_marginLeft="30dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:fontFamily="@font/telly_humble"
    android:textSize="35dp"
    android:text="jay" />

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-22
  • 1970-01-01
  • 2018-01-16
  • 2016-08-01
相关资源
最近更新 更多