【问题标题】:Android cursor in RTL languagesRTL 语言中的 Android 光标
【发布时间】:2016-05-24 12:16:38
【问题描述】:

我对 RTL 语言中的 android 输入光标有疑问。当我在 RTL 支持布局中时,我有两个输入光标,这真的很有趣。 它有真正的解决方案,摆脱这个吗?

我使用这段代码来制作我的 android UI RTL:

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

这是我用于文本视图的 xml:

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:id="@+id/myID"
            android:maxLines="1"
            android:focusableInTouchMode="true"
            android:layout_weight="0.25"
            android:layout_gravity="center_horizontal"
            android:hint="phone Number"
            android:maxLength="20"
            android:gravity="center" />
    </android.support.design.widget.TextInputLayout>

【问题讨论】:

  • 我可能是因为您已将edittext 重力设置为中心并且光标混淆了。这不应该发生,但尝试左右重力然后可能不会出现问题。最好你给重力值开始
  • @CreativeAndroid 我做了你所说的一切,但仍然是同样的问题。
  • 发布您的edittext xml
  • @CreativeAndroid 我发了,请查看。谢谢
  • 我认为你强行将其设置为 RTL

标签: android layout right-to-left text-cursor


【解决方案1】:

保留android:inputType="phone" 而不是android:inputType="number" 解决了我的问题。

以下 sn-p 来自我的 xml:

<EditText
    android:hint="xyzz"
    android:inputType="phone"
    android:id="@+id/num"
    android:textColorHint="#000000"
    android:layout_gravity="start"
    android:textAlignment="viewStart"
    android:textDirection="rtl"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_width="match_parent"
    tools:ignore="RtlCompat" />

【讨论】:

    【解决方案2】:

    我用下面的方法解决了..

    在您的 xml 布局中,为编辑文本字段添加这个-->

    android:textDirection="anyRtl"
    

    这里,“editText”是您对编辑文本字段的看法。即,

    EditText editText = (EditText) findViewById(R.id.edit_text); 
    

    然后以编程方式为该编辑文本添加文本观察器。

    editText.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                    }
    
                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        editText.setSelection(s.length()); // this line is very important for setting cursor position
                    }
    
                    @Override
                    public void afterTextChanged(Editable s) {
    
                    }
                });
            }
    

    这对我有用!

    【讨论】:

      【解决方案3】:

      我解决了这个问题。 只需将编辑文本语言从左到右,问题就解决了。

      <EditText
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:inputType="number"
          android:ems="10"
          android:id="@+id/PhoneNoET"
          android:layout_marginTop="64dp"
          android:layout_below="@+id/textView6"
          android:layout_centerHorizontal="true"
          android:textAlignment="center"
          android:maxLength="11" 
          android:layoutDirection="ltr"/>
      

      将上述 layoutDirection 添加到您的编辑文本并修复问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-29
        • 1970-01-01
        • 1970-01-01
        • 2022-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-18
        相关资源
        最近更新 更多