6

我有一个 EditText 设置为重力右,因此如果语言是阿拉伯语,则文本从右侧开始。

注意:我的应用程序支持 RTL,我没有为我的 EditText 设置 TextDirection,因为那样会有同样的问题。重力设置为右完美地完成了这项工作。仅当我将 InputType 设置为 Number 或 Phone 时才会出现问题。

如果 InputType 设置为 number/phone,则文本的开头和结尾会有双光标,这有点令人困惑。

为了证明这一点,我有两个带有 InputType 文本和数字的 EditText,两者的 Gravity 都设置为 Right。我的应用程序支持 RTL,我的手机现在设置为阿拉伯语

显现

android:supportsRtl="true"

XML

 <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="text"
            android:inputType="text"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right"
            />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/phone"
            android:inputType="number"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right"
            />

这是带有 InputType Number 的第二个 EditText 行为的屏幕截图。

关于如何摆脱双光标的任何指示?或任何替代方案。

谢谢R

在此处输入图像描述

4

5 回答 5

2

使用属性 layout_direction 作为'ltr'和重力'right'。

      <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/phone"
            android:inputType="number"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right" />

这解决了我的问题。

于 2018-11-01T05:35:29.323 回答
1

编辑文本不知道您将按下的下一个字符是数字还是字母,因此如果是字母,它会将最左边的一个放在最右边的一个用于数字(很可能您知道只是确保) .

因此,如果您切换到英语,它将消失。

我认为这是编辑文本的基础:

解决方案:

1-您可以从头开始创建自己的编辑文本(从视图)。(可能需要一个月的时间来解决可能出现的所有问题)。

2-找到一种方法来覆盖编辑文本以删除拆分。

3-找到一个有人解决了这个问题的git(我怀疑)。


作为程序员或用户,这似乎不是问题。设计师可能会有点恼火,但忽略它是最快的方法。

对不起,如果这没有用。

于 2018-01-29T09:52:40.423 回答
0
ViewCompat.setLayoutDirection(findViewById(R.id.myedittext), ViewCompat.LAYOUT_DIRECTION_LTR);

它对我有用。

于 2018-03-28T10:15:46.447 回答
0

使用水平方向和 layoutDirection ltr 将编辑文本包装在线性布局中

于 2020-04-21T09:23:58.690 回答
0

android:inputType="number"换手机试试。。

例如 :

   <com.test.utils.custom.CustomTelephone
    android:id="@+id/custom_telephone"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:inputType="phone"
    android:text="@string/telephone_number_title"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/iv_logo" />

这对我有用..

如果不起作用,请尝试在编辑文本中添加 layoutDirection:Rtl 作为属性..快乐编码..!

于 2021-06-16T15:36:00.950 回答