2017-05-10 24 views
2

我有我想要的EditText向上滑動(與屏幕的其餘部分)一個多語種的應用程序時,其上的用戶點擊,即EditText應該總是只要顯示鍵盤,鍵盤上方都會顯示Android的 - 如何語言環境影響窗口軟輸入模式

enter image description here

顯然使用android:windowSoftInputMode="adjustResize"這是可行的。

不幸的是,這似乎只在應用程序語言是英文時才能正常工作。當用戶將應用程序語言更改爲阿拉伯語時,EditText在所有低於7.1.1的操作系統版本上僅在第一次上方滑動到鍵盤上方。它在Android 7.1.1上按預期工作。

enter image description here

這是一個已知的問題與棉花糖6.0.1和較低的版本?有沒有解決這個問題的方法或解決方法?

+0

這是預-N設備問題 – xbadal

回答

0

要解決此問題,您需要創建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"