RTL语言中的Android游标
我对RTL语言中的android输入游标有问题。当我在RTL支持布局中时,我有两个输入光标,这真的很有趣。 它有真正的解决办法吗,为了摆脱这个 我使用以下代码来创建我的android UI RTL:RTL语言中的Android游标,android,layout,cursor,right-to-left,Android,Layout,Cursor,Right To Left,我对RTL语言中的android输入游标有问题。当我在RTL支持布局中时,我有两个输入光标,这真的很有趣。 它有真正的解决办法吗,为了摆脱这个 我使用以下代码来创建我的android UI RTL: getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 这是我的xml文本视图: <android.support.design.widget.TextInputLayout andr
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
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"/>
将上面的布局方向添加到编辑文本中并解决问题。我使用下面的方法解决了它
在xml布局中,为“编辑文本”字段添加以下内容-->
这里,“editText”是编辑文本字段的视图。i、 e
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) {
}
});
}
这对我有用 保留android:inputType=“phone”
而不是android:inputType=“number”
解决了我的问题
以下代码段来自我的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" />
我可能是因为您将edittext重力设置为中心,光标被弄糊涂了。这不应该发生,但试试左右重力,问题可能不会出现。你最好给出重力值start@CreativeAndroid你说的我都做了,问题还是一样。发你的编辑文本xml@CreativeAndroid我贴了,请查收。谢谢,我想你把它强制设置为RTL
<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" />