我正在使用Kotlin。我使用了正确的重力,因此输入数字从右开始。但是EditText光标始终保持在EditText中输入文本的左侧。我想保持重力向右,文字从右向左。这是图像
这是我的EditText xml代码。
<EditText
android:id="@+id/et_amount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:ellipsize="end"
android:gravity="right|center_horizontal|center_vertical"
android:textStyle="bold"
android:maxLength="6" >
<requestFocus />
</EditText>
请帮助我,以便输入文本从左到右开始并且光标始终显示为正确。
答案 0 :(得分:1)
尝试一下:
EditText text = new EditText(context);
text.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) {
}
@Override
public void afterTextChanged(Editable s) {
String text1 = text.getText().toString();
text.setText(text1);
text.setSelection(text1.length());
}
});
这将是可行的;
希望能为您提供帮助
答案 1 :(得分:0)
尝试将其添加到您的编辑文本中:
android:textDirection="rtl"