/** * Hides the soft keyboard */ public void hideSoftKeyboard() { if(getCurrentFocus()!=null) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } /** * Shows the soft keyboard */ public void showSoftKeyboard(View view) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); view.requestFocus(); inputMethodManager.showSoftInput(view, 0); }
private void requestPlayPauseFocus() { boolean playing = isPlaying(); if (!playing && playButton != null) { playButton.requestFocus(); } else if (playing && pauseButton != null) { pauseButton.requestFocus(); } }
public static void showSoftInput(Context context, View view, boolean requestFocus) { if (requestFocus) { view.requestFocus(); } InputMethodManager imm = (InputMethodManager) context.getSystemService(Service.INPUT_METHOD_SERVICE); imm.showSoftInput(view, 0); }
protected final void openInputMethod(View view) { view.requestFocus(); InputMethodManager manager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (manager != null) { manager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } }
public static void showKeyboard(final View view) { view.requestFocus(); InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(view, 0); }
webview.requestFocus(View.FOCUS_DOWN); webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
@Override public boolean onTouch(View v, MotionEvent event) { if (!v.hasFocus()) { v.requestFocus(); } return false; } });
@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); } }
webView.requestFocus(View.FOCUS_DOWN); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } 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); }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mImapPathPrefixView.setEnabled(!isChecked); if (isChecked && mImapPathPrefixView.hasFocus()) { mImapPathPrefixView.focusSearch(View.FOCUS_UP).requestFocus(); } else if (!isChecked) { mImapPathPrefixView.requestFocus(); } } });
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.focusable_button); initActionBar(); button=findViewById(R.id.button1); button.requestFocus(View.FOCUS_RIGHT); button.setOnClickListener(this); }
v.setFocusable(true); v.setFocusableInTouchMode(true); v.requestFocus();
v.setFocusable(true); v.setFocusableInTouchMode(true); v.requestFocus();
void toggleShowExtraKeys() { final ViewPager viewPager = findViewById(R.id.viewpager); final boolean showNow = mSettings.toggleShowExtraKeys(TermuxActivity.this); viewPager.setVisibility(showNow ? View.VISIBLE : View.GONE); if (showNow && viewPager.getCurrentItem() == 1) { // Focus the text input view if just revealed. findViewById(R.id.text_input).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; } }); }
@Test public void clearFocus_shouldRecursivelyClearTheFocusOfAllChildren() throws Exception { child3a.requestFocus(); root.clearFocus(); assertFalse(child3a.hasFocus()); assertFalse(child3.hasFocus()); assertFalse(root.hasFocus()); root.requestFocus(); root.clearFocus(); assertFalse(root.hasFocus()); }
@Test public void hasFocus_shouldReturnTrueIfAnyChildHasFocus() throws Exception { makeFocusable(root, child1, child2, child3, child3a, child3b); assertFalse(root.hasFocus()); child1.requestFocus(); assertTrue(root.hasFocus()); child1.clearFocus(); assertFalse(child1.hasFocus()); assertTrue(root.hasFocus()); child3b.requestFocus(); assertTrue(root.hasFocus()); child3b.clearFocus(); assertFalse(child3b.hasFocus()); assertFalse(child3.hasFocus()); assertTrue(root.hasFocus()); child2.requestFocus(); assertFalse(child3.hasFocus()); assertTrue(child2.hasFocus()); assertTrue(root.hasFocus()); root.requestFocus(); assertTrue(root.hasFocus()); }