下面列出了android.widget.EditText#setLongClickable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setAllowSystemKeyboardOnEditText(EditText editText, boolean allowSystemKeyboard) {
// TODO this needs to be tested on lower versions!
// https://stackoverflow.com/a/45229457
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // api 21+
editText.setShowSoftInputOnFocus(allowSystemKeyboard);
} else { // api 11+
if (allowSystemKeyboard) {
// re-enable keyboard (see https://stackoverflow.com/a/45228867)
// FIXME this does not necessarily always work
editText.setTextIsSelectable(false);
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);
editText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
editText.setText(editText.getText(), TextView.BufferType.SPANNABLE);
} else {
// disable keyboard
editText.setTextIsSelectable(true);
}
}
}
/**
* Whether or not the digits above the dialer can be edited.
*
* @param canBeEdited If true, the backspace button will be shown and the digits EditText
* will be configured to allow text manipulation.
*/
public void setDigitsCanBeEdited(boolean canBeEdited) {
View deleteButton = findViewById(R.id.button_delete);
deleteButton.setVisibility(canBeEdited ? View.VISIBLE : View.GONE);
View callButton = findViewById(R.id.button_call);
callButton.setVisibility(canBeEdited ? View.VISIBLE : View.GONE);
EditText digits = (DigitsEditText) findViewById(R.id.digits_edit_text);
digits.setClickable(canBeEdited);
digits.setLongClickable(canBeEdited);
digits.setFocusableInTouchMode(canBeEdited);
digits.setCursorVisible(canBeEdited);
}