@Override public boolean onTouch (View view, MotionEvent event) { if (requestFocus && view != null) { view.setFocusableInTouchMode(true); view.requestFocus(); requestFocus = false; } // synchronized in handler.postTouchEvent() touchHandler.onTouch(event, this); if (sleepTime != 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } } return true; }
@Override public boolean onTouch (View view, MotionEvent event) { if (requestFocus && view != null) { view.setFocusableInTouchMode(true); view.requestFocus(); requestFocus = false; } // synchronized in handler.postTouchEvent() touchHandler.onTouch(event, this); if (sleepTime != 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } } return true; }
/** * 弹出输入法 * * @param context context * @param view 编辑控件 */ public static void setEditFocusable(final Context context, final View view) { view.setFocusableInTouchMode(true); view.requestFocus(); InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(view, 0); } }
etBonus.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.setFocusable(true); v.setFocusableInTouchMode(true); return false; } });
/** * 显示软键盘 * * @param view */ public static void showSoftKeyboard(View view) { Context context = view.getContext(); InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); view.setFocusable(true); view.setFocusableInTouchMode(true); view.requestFocus(); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); }
mDragView.setClickable(true); mDragView.setFocusable(false); mDragView.setFocusableInTouchMode(false); mDragView.setOnClickListener(new OnClickListener() { @Override
/** * Set the draggable view portion. Use to null, to allow the whole panel to be draggable * * @param dragView A view that will be used to drag the panel. */ public void setDragView(View dragView) { if (mDragView != null && mDragViewClickable) { mDragView.setOnClickListener(null); } mDragView = dragView; if (mDragView != null) { mDragView.setClickable(true); mDragView.setFocusable(false); mDragView.setFocusableInTouchMode(false); if (mDragViewClickable) { mDragView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!isEnabled()) return; if (!isPanelExpanded() && !isPanelAnchored()) { expandPanel(mAnchorPoint); } else { collapsePanel(); } } }); } } }
public void run () { InputMethodManager manager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); if (visible) { View view = ((AndroidGraphics)app.getGraphics()).getView(); view.setFocusable(true); view.setFocusableInTouchMode(true); manager.showSoftInput(((AndroidGraphics)app.getGraphics()).getView(), 0); } else { manager.hideSoftInputFromWindow(((AndroidGraphics)app.getGraphics()).getView().getWindowToken(), 0); } } });
public void run () { InputMethodManager manager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); if (visible) { View view = ((AndroidGraphics)app.getGraphics()).getView(); view.setFocusable(true); view.setFocusableInTouchMode(true); manager.showSoftInput(((AndroidGraphics)app.getGraphics()).getView(), 0); } else { manager.hideSoftInputFromWindow(((AndroidGraphics)app.getGraphics()).getView().getWindowToken(), 0); } } });
@BindingAdapter("app:requestFocus") public static void bindRequestFocus(View v, String focusMode) { Configuration cfg=v.getResources().getConfiguration(); boolean hasNoKeyboard= cfg.keyboard==Configuration.KEYBOARD_NOKEYS; boolean keyboardHidden= cfg.hardKeyboardHidden==Configuration.HARDKEYBOARDHIDDEN_YES; boolean result=false; if (TRUE.equals(focusMode)) { result=true; } else if (IF_HARD_KEYBOARD.equals(focusMode)) { if (!hasNoKeyboard && !keyboardHidden) { result=true; } } else if (IF_NO_HARD_KEYBOARD.equals(focusMode)) { if (hasNoKeyboard || keyboardHidden) { result=true; if (hasNoKeyboard) v.setFocusableInTouchMode(true); } } else { throw new IllegalArgumentException("Unexpected focusMode value: "+focusMode); } if (result) { v.setFocusable(true); v.requestFocus(); } }
public AndroidGraphics (AndroidApplicationBase application, AndroidApplicationConfiguration config, ResolutionStrategy resolutionStrategy, boolean focusableView) { AndroidGL20.init(); this.config = config; this.app = application; view = createGLSurfaceView(application, resolutionStrategy); preserveEGLContextOnPause(); if (focusableView) { view.setFocusable(true); view.setFocusableInTouchMode(true); } }
public AndroidGraphics (AndroidApplicationBase application, AndroidApplicationConfiguration config, ResolutionStrategy resolutionStrategy, boolean focusableView) { AndroidGL20.init(); this.config = config; this.app = application; view = createGLSurfaceView(application, resolutionStrategy); preserveEGLContextOnPause(); if (focusableView) { view.setFocusable(true); view.setFocusableInTouchMode(true); } }
v.setOnTouchListener(this); v.setFocusable(true); v.setFocusableInTouchMode(true); v.requestFocus();
v.setOnTouchListener(this); v.setFocusable(true); v.setFocusableInTouchMode(true); v.requestFocus();
@Override public void onResume() { super.onResume(); //这样监听返回键有个缺点就是没有拦截Activity的返回监听,如果有更优方案可以改掉 getView().setFocusableInTouchMode(true); getView().requestFocus(); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { if (isVisible(llBatchManagement)) { goneBatchManagementAndRefreshUI(); return true; } } return false; } }); }
public void configureCustom(View content) { markConfigured(true); // The focused state should be rendered by the content. setBackgroundDrawable(null); // Prevent the content from receiving events, but let it reflect the correct state. content.setFocusable(false); content.setFocusableInTouchMode(false); content.setClickable(false); content.setDuplicateParentStateEnabled(true); removeAllViews(); addView(content); }
@Override protected void mutate(Boolean value) { view.setFocusableInTouchMode(value); } });
EditText edPwd = (EditText)findViewById(R.id.password); edtPwd.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.setFocusable(true); v.setFocusableInTouchMode(true); return false; } });
/** * 禁用 contentView,让其失去焦点不可接受点击 */ private void disableContentView() { contentView.setPressed(false); contentView.setFocusable(false); contentView.setFocusableInTouchMode(false); }
private void test(){ LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View contentview = inflater.inflate(R.layout.pop_layout1, null); final PopupWindow popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); //popupWindow popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(false); popupWindow.setBackgroundDrawable(null); popupWindow.getContentView().setFocusable(true); // 这个很重要 popupWindow.getContentView().setFocusableInTouchMode(true); popupWindow.getContentView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { popupWindow.dismiss(); return true; } return false; } }); popupWindow.showAsDropDown(mButton1, 0, 10); }