下面列出了android.widget.EditText#setFocusableInTouchMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private KeyboardHelper(@NonNull Activity activity) {
super(activity);
this.statusBarHeight = getStatusBarHeight();
int sizeForDummyView = activity.getResources()
.getDimensionPixelSize(zendesk.belvedere.ui.R.dimen.belvedere_dummy_edit_text_size);
setLayoutParams(new ViewGroup.LayoutParams(sizeForDummyView, sizeForDummyView));
inputTrap = new EditText(activity);
inputTrap.setFocusable(true);
inputTrap.setFocusableInTouchMode(true);
inputTrap.setVisibility(View.VISIBLE);
inputTrap.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
inputTrap.setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
addView(inputTrap);
final View rootView = activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new KeyboardTreeObserver(activity));
}
public AlertDialog.Builder editTextDisabled(final TextView text, final TextView title, String message) {
LayoutInflater factory = LayoutInflater.from(context);
final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_edit_text_float_2_4, null);
final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
final TextView messageView = new TextView(this.context);
messageView.setText(message);
messageView.setGravity(Gravity.CENTER);
alertView.addView(messageView);
// Set text
editText.setText(text.getText().toString());
// Set disabled.
editText.setEnabled(false);
editText.setClickable(false);
editText.setFocusable(false);
editText.setFocusableInTouchMode(false);
return new AlertDialog.Builder(context)
.setTitle(title.getText().toString())
.setView(alertView)
.setPositiveButton(R.string.ok, null);
}
@WXComponentProp(name = Constants.Name.AUTOFOCUS)
public void setAutofocus(boolean autofocus) {
if (getHostView() == null) {
return;
}
mAutoFocus = autofocus;
EditText inputView = getHostView();
if (mAutoFocus) {
inputView.setFocusable(true);
inputView.requestFocus();
inputView.setFocusableInTouchMode(true);
showSoftKeyboard();
} else {
hideSoftKeyboard();
}
}
/**
* EditText重新获取焦点的事件绑定
*/
@BindingAdapter(value = {"requestFocus"}, requireAll = false)
public static void requestFocusCommand(EditText editText, final Boolean needRequestFocus) {
if (needRequestFocus) {
editText.setSelection(editText.getText().length());
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
editText.setFocusableInTouchMode(needRequestFocus);
}
public void resetView(){
this.source = (ScriptSourceConfig)MainActivity.script;
TextView title = (TextView)findViewById(R.id.title);
title.setText(Utils.stripTags(this.instance.name));
String script = source.source;
EditText editScript = (EditText)findViewById(R.id.scriptSource);
Button saveButton = (Button)findViewById(R.id.saveScriptButton);
if (script != null && !script.equals("")) {
editScript.setText(script);
}
else {
editScript.setText("");
}
boolean isAdmin = (MainActivity.user != null) && instance.isAdmin;
if (!isAdmin || instance.isExternal) {
editScript.setFocusable(false);
saveButton.setEnabled(false);
saveButton.setVisibility(View.GONE);
} else {
editScript.setFocusableInTouchMode(true);
saveButton.setEnabled(true);
}
}
/**
* 开启软键盘
* @param et
*/
public static void openSoftKeyboard(EditText et) {
if (et != null) {
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();
InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(et, 0);
}
}
/**
* 针对于EditText 获得焦点,显示软键盘
*
* @param edit EditText
*/
public void showKeyboard(EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
imm.showSoftInput(edit, 0);
}
private void setDatePickerInputLayout(final EditText editText, final int position, final LinearLayout layoutRow) {
editText.setFocusableInTouchMode(false);
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
layoutRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clickedPosition = position;
DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
date,
mCalendarCurrentDate.get(Calendar.YEAR),
mCalendarCurrentDate.get(Calendar.MONTH),
mCalendarCurrentDate.get(Calendar.DAY_OF_MONTH));
// this could be used to set a minimum date
// datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
// display the picker
datePickerDialog.show();
}
});
}
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void showSoftInput(Context context, EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edit, 0);
}
public static void showSoftInputFromWindow(EditText editText)
{
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
}
/**
* 动态显示软键盘
*
* @param edit 输入框
*/
public static void showSoftInput(EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager imm = (InputMethodManager) Utils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) return;
imm.showSoftInput(edit, 0);
}
/**
* 动态显示软键盘
*
* @param context 上下文
* @param edit 输入框
*/
public static void showSoftInput(Context context, EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edit, 0);
}
/**
* 切换键盘显示与否状态
*
* @param context 上下文
* @param edit 输入框
*/
public static void toggleSoftInput(Context context, EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
/**
* 动态显示软键盘
*/
public static void showSoftInput(Context context, EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edit, 0);
}
/**
* EditText获取焦点并显示软键盘
*/
public static void showSoftInputFromWindow(EditText editText, Activity activity) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
/**
* 开启软键盘
* @param et
*/
public static void openSoftKeyboard(EditText et) {
if (et != null) {
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();
InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(et, 0);
}
}
public static void showSoftInput(EditText edit, Context context) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager imm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edit, 0);
}
public void setView(View view)
{
LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView);
l.removeAllViews();
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(layoutParams);
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override public void onFocusChange(View v, boolean hasFocus)
{
mAlertDialogWindow.setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
// show imm
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
});
l.addView(view);
if (view instanceof ViewGroup)
{
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++)
{
if (viewGroup.getChildAt(i) instanceof EditText)
{
EditText editText = (EditText) viewGroup.getChildAt(i);
editText.setFocusable(true);
editText.requestFocus();
editText.setFocusableInTouchMode(true);
}
}
for (int i = 0; i < viewGroup.getChildCount(); i++)
{
if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView)
{
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup
.getChildAt(i);
autoCompleteTextView.setFocusable(true);
autoCompleteTextView.requestFocus();
autoCompleteTextView.setFocusableInTouchMode(true);
}
}
}
}
private void enableEditText(EditText editText) {
editText.setEnabled(true);
editText.setFocusableInTouchMode(true);
}
/**
* 文本编辑器
*/
private void bindEditComponent(RecyclerView.ViewHolder holder, final int pos, final
RichModel item) {
if (holder instanceof EditHolder) {
final EditText mEdit = ((EditHolder) holder).mEt;
mEtHolder.add(mEdit);
if (index == pos) {
mCurEdit = ((EditHolder) holder).mEt;
mEdit.setFocusable(true);
mEdit.setFocusableInTouchMode(true);
mEdit.requestFocus();
} else {
mEdit.setFocusable(false);
}
((EditHolder) holder).textWatcher.updatePosition(pos);
((EditHolder) holder).filter.updatePosition(pos);
mEdit.setTextSize(Const.DEFAULT_TEXT_SIZE);
if (item.isParagraphStyle) {
SpannableStringBuilder spannableString = new SpannableStringBuilder(item.source);
for (Object obj : item.paragraphSpan.mSpans) {
if (obj instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan sizeSpan = (AbsoluteSizeSpan) obj;
mEdit.setTextSize(sizeSpan.getSize());
continue;
}
spannableString.setSpan(obj, 0, item.source.length(), Spanned
.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mEdit.setText(spannableString);
paragraphHelper.handleTextStyle(mEdit, item.paragraphSpan.paragraphType);
} else {
mSpanString.clear();
mSpanString.clearSpans();
mSpanString.append(item.source);
if (isEnter) {
for (SpanModel span : item.getSpanList()) {
mSpanString.setMultiSpans(span.mSpans, span.start, span.end, Spanned
.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
mEdit.setText(mSpanString);
paragraphHelper.handleTextStyle(mEdit, -1);
}
mEdit.setSelection(item.curIndex);
//mEdit.setSelection(item.source.length());
mEdit.setHint(item.hint);
mEdit.setTag(pos);
//只存在一个EditText的时候,点击区域太小,所以只有一个的时候,将MinHeight设为500
if (index == pos && index < 2 && index == mData.size() - 1) {
mEdit.setMinHeight(DensityUtil.dp2px(mContext, 500));
} else {
mEdit.setMinHeight(DensityUtil.dp2px(mContext, 0));
}
}
}