Android - 键盘覆盖阿拉伯语/RTL 中的 EditText

Android - keyboard covering EditText in Arabic / RTL

我有一个多语言应用程序,我希望 EditText 在用户单击它时向上滑动(与屏幕的其余部分一起),即 EditText 应该 总是 在键盘上方可见,只要显示键盘。

显然这可以使用 android:windowSoftInputMode="adjustResize"

不幸的是,这似乎只有在应用语言为英语时才能正常工作。当用户将应用程序语言更改为阿拉伯语时,EditText 在键盘上方滑动 仅第一次 在所有 OS 版本低于 7.1.1。它在 Android 7.1.1.

上按预期工作

这是 Marshmallow 6.0.1 及更低版本的已知问题吗?是否有破解方法或解决方法来规避此问题?

要解决此问题,您需要创建 customEditText 和覆盖 这对我有用。

public class CustomEditText extends android.support.v7.widget.AppCompatEditText {

Context context;

public CustomEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
}

@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        public static void hideKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}

        clearFocus();
    }
    return false;
}

}

然后在 xml

中添加两行
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

一个简单的 way.you 可以设置 edittext 重力以在 RTL 中显示阿拉伯语,如 below.either 在 xml 中,或者您可以动态地进行。

在 xml 中执行此操作

 <EditText
    android:padding="15dp"
    android:layout_width="fill_parent"
    android:hint="رمز القسيمة الاختياري"
    android:id="@+id/register"
    android:textColorHint="#d3d3d3"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:background="@android:color/transparent"
    android:textColor="#000000"
    android:textSize="14sp"
   />

动态你可以这样设置

 textmob.setGravity(Gravity.RIGHT); //textmob is object

注意:您可以对 textview 元素执行此操作