类android.view.inputmethod.InputMethodManager源码实例Demo

下面列出了怎么用android.view.inputmethod.InputMethodManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: NHentai-android   文件: SearchBox.java
private void closeSearch() {
	this.materialMenu.animateState(IconState.BURGER);
	this.logo.setVisibility(View.VISIBLE);
	this.drawerLogo.setVisibility(View.VISIBLE);
	this.search.setVisibility(View.GONE);
	this.results.setVisibility(View.GONE);
	if (tint != null && rootLayout != null) {
		rootLayout.removeView(tint);
	}
	if (listener != null)
		listener.onSearchClosed();
	micStateChanged(true);
	mic.setImageDrawable(context.getResources().getDrawable(
			R.drawable.ic_action_mic));
	InputMethodManager inputMethodManager = (InputMethodManager) context
			.getSystemService(Context.INPUT_METHOD_SERVICE);
	inputMethodManager.hideSoftInputFromWindow(getApplicationWindowToken(),
			0);
}
 
源代码2 项目: test-samples   文件: ES_ExternalStorage.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.es_layout);

    inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);

    et_file = (EditText) findViewById(R.id.es_et_file);
    et_error = (EditText) findViewById(R.id.es_et_error);
    b_read = (Button) findViewById(R.id.es_b_read);
    tv_output = (TextView) findViewById(R.id.es_tv_output);

    et_file.setText(DEFAULT_FILE);

    b_read.setOnClickListener(this);
}
 
源代码3 项目: mollyim-android   文件: RestoreBackupFragment.java
private void handleRestore(@NonNull Context context, @NonNull BackupUtil.BackupInfo backup) {
  View     view   = LayoutInflater.from(context).inflate(R.layout.enter_backup_passphrase_dialog, null);
  EditText prompt = view.findViewById(R.id.restore_passphrase_input);

  prompt.addTextChangedListener(new PassphraseAsYouTypeFormatter());

  new AlertDialog.Builder(context)
                 .setTitle(R.string.RegistrationActivity_enter_backup_passphrase)
                 .setView(view)
                 .setPositiveButton(R.string.RegistrationActivity_restore, (dialog, which) -> {
                   InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                   inputMethodManager.hideSoftInputFromWindow(prompt.getWindowToken(), 0);

                   setSpinning(restoreButton);
                   skipRestoreButton.setVisibility(View.INVISIBLE);

                   String passphrase = prompt.getText().toString();

                   restoreAsynchronously(context, backup, passphrase);
                 })
                 .setNegativeButton(android.R.string.cancel, null)
                 .show();

  Log.i(TAG, "Prompt for backup passphrase shown to user.");
}
 
源代码4 项目: BonjourBrowser   文件: RegisterServiceActivity.java
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (getView() == null || actionId != EditorInfo.IME_ACTION_DONE) {
        return false;
    }
    switch (v.getId()) {
        case R.id.service_name:
            regTypeEditText.requestFocus();
            return true;
        case R.id.reg_type:
            portEditText.requestFocus();
            return true;
        case R.id.port:
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
            return true;
    }
    return false;
}
 
源代码5 项目: MinMinGuard   文件: UIUtils.java
static public void restartApp(Context context, String packageName)
{
    ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
    am.killBackgroundProcesses(packageName);

    Intent it = context.getPackageManager().getLaunchIntentForPackage(packageName);
    Activity a = (Activity) context;
    if (it != null)
    {
        if (a.getCurrentFocus() != null)
        {
            ((InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(a.getCurrentFocus().getWindowToken(), 0);
        }

        it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(it);
    }
    else
    {
        Toast.makeText(context, context.getString(R.string.msg_app_launch_fail), Toast.LENGTH_SHORT).show();
    }
}
 
源代码6 项目: Klyph   文件: StreamFragment.java
private void postComment()
{
	if (sendEditText.getText().toString().length() > 0)
	{
		Bundle params = new Bundle();
		params.putString("message", sendEditText.getText().toString());

		InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(sendEditText.getWindowToken(), 0);

		sendRequest(params);
	}
	else
	{
		AlertUtil.showAlert(getActivity(), R.string.error, R.string.define_comment_before_publish, R.string.ok);
	}
}
 
源代码7 项目: phonegapbootcampsite   文件: InAppBrowser.java
/**
 * Navigate to the new page
 *
 * @param url to load
 */
private void navigate(final String url) {
    InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            if (!url.startsWith("http") && !url.startsWith("file:")) {
                InAppBrowser.this.inAppWebView.loadUrl("http://" + url);
            } else {
                InAppBrowser.this.inAppWebView.loadUrl(url);
            }
            InAppBrowser.this.inAppWebView.requestFocus();
        }
    });
}
 
源代码8 项目: TelePlus-Android   文件: AndroidUtilities.java
public static void hideKeyboard(View view)
{
    if (view == null)
    {
        return;
    }
    try
    {
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!imm.isActive())
        {
            return;
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
源代码9 项目: zap-android   文件: HomeActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //NFC
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    mInputMethodManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    mHandler = new Handler();

    mUnlockDialog = buildUnlockDialog();

    // Register observer to detect if app goes to background
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);

    // Set wallet fragment as beginning fragment
    mFt = getSupportFragmentManager().beginTransaction();
    mCurrentFragment = new WalletFragment();
    mFt.replace(R.id.mainContent, mCurrentFragment);
    mFt.commit();

    // Setup Listener
    BottomNavigationView navigation = findViewById(R.id.mainNavigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
源代码10 项目: Social   文件: EaseBaseActivity.java
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    //理论上应该放在launcher activity,放在基类中所有集成此库的app都可以避免此问题
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
源代码11 项目: xmpp   文件: NewsContentActivity.java
/**
 * 初始化控件
 */
private void initialView() {
    initViewPager();
    DialogView.Initial(this, "正在评论......");


    imm = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
    mPager = (ViewPager) findViewById(R.id.news_content_vPager);
    mPager.setOnPageChangeListener(this);

    et_pinglun = (EditText) findViewById(R.id.news_content_editText_pinglun);
    tv_pinglun = (TextView) findViewById(R.id.news_content_text_showpinglun);
    tv_uppinglun = (TextView) findViewById(R.id.news_content_text_enterpinglun);
    tv_pinglun.setText(content.getCpinglun() + "评");

    back = (LinearLayout) findViewById(R.id.news_content_back);
    back.setOnClickListener(this);

    tv_pinglun.setOnClickListener(this);
    tv_uppinglun.setOnClickListener(this);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(0);
}
 
源代码12 项目: memetastic   文件: ActivityUtils.java
public ActivityUtils setSoftKeyboardVisibile(boolean visible, View... editView) {
    final Activity activity = _activity;
    if (activity != null) {
        final View v = (editView != null && editView.length > 0) ? (editView[0]) : (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null ? activity.getCurrentFocus() : null);
        final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (v != null && imm != null) {
            Runnable r = () -> {
                if (visible) {
                    v.requestFocus();
                    imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
                } else {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            };
            r.run();
            for (int d : new int[]{100, 350}) {
                v.postDelayed(r, d);
            }
        }
    }
    return this;
}
 
源代码13 项目: RxZhihuDaily   文件: BaseFragment.java
protected void showKeyboard() {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }

    if (activity.getCurrentFocus() == null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    } else {
        imm.showSoftInput(activity.getCurrentFocus(), 0);
    }
}
 
源代码14 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * {@inheritDoc}
 */
@MainThread
@Override
public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
    if (DEBUG) Log.v(TAG, "hideSoftInput()");
    boolean wasVis = isInputViewShown();
    mShowInputFlags = 0;
    mShowInputRequested = false;
    doHideWindow();
    clearInsetOfPreviousIme();
    if (resultReceiver != null) {
        resultReceiver.send(wasVis != isInputViewShown()
                ? InputMethodManager.RESULT_HIDDEN
                : (wasVis ? InputMethodManager.RESULT_UNCHANGED_SHOWN
                        : InputMethodManager.RESULT_UNCHANGED_HIDDEN), null);
    }
}
 
源代码15 项目: jmonkeyengine   文件: JmeAndroidSystem.java
@Override
public void showSoftKeyboard(final boolean show) {
    view.getHandler().post(new Runnable() {

        @Override
        public void run() {
            InputMethodManager manager =
                    (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

            if (show) {
                manager.showSoftInput(view, 0);
            } else {
                manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        }
    });
}
 
源代码16 项目: mosby   文件: KeyboardUtils.java
/**
 * Hides the soft keyboard from screen
 *
 * @param view Usually the EditText, but in dynamically  layouts you should pass the layout
 * instead of the EditText
 * @return true, if keyboard has been hidden, otherwise false (i.e. the keyboard was not displayed
 * on the screen or no Softkeyboard because device has hardware keyboard)
 */
public static boolean hideKeyboard(View view) {

  if (view == null) {
    throw new NullPointerException("View is null!");
  }

  try {
    InputMethodManager imm =
        (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    if (imm == null) {
      return false;
    }

    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  } catch (Exception e) {
    return false;
  }

  return true;
}
 
源代码17 项目: AndroidApp   文件: EditPoiFragment.java
private void closeFragment() {
    ((MainActivity) getActivity()).showNavigationNoFab();
    getActivity()
            .getSupportFragmentManager()
            .beginTransaction()
            .remove(EditPoiFragment.this)
            .commit();

    //Close keyboard
    // Check if no view has focus:
    View view = getActivity().getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
 
源代码18 项目: LiuAGeAndroid   文件: SearchEditText.java
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    pressSearch = (keyCode == KeyEvent.KEYCODE_ENTER);
    if (pressSearch && listener != null) {
        /*隐藏软键盘*/
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
        }
        if (event.getAction() == KeyEvent.ACTION_UP) {
            pressSearch = false;
            listener.onSearchClick(v);
        }
    }
    return false;
}
 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =  inflater.inflate(R.layout.fragment_login, container, false);
    ButterKnife.inject(this,view);

    USERNAME = getString(R.string.login_username);
    PASSWORD = getString(R.string.login_password);
    FAIL_MESSAGE = getString(R.string.login_fail_message);
    SUCCESS_MESSAGE = getString(R.string.login_success_message);
    ALT_BUTTON_FAIL_TITLE = getString(R.string.try_login_again_button_title);
    ALT_BUTTON_SUCCESS_TITLE = getString(R.string.logout_button_title);

    imm = (InputMethodManager)getActivity().getSystemService(getActivity().getApplicationContext().INPUT_METHOD_SERVICE);

    return view;
}
 
源代码20 项目: edx-app-android   文件: SoftKeyboardUtil.java
/**
 * Hides the soft keyboard.
 *
 * @param activity The reference of the activity displaying the keyboard.
 */
public static void hide(@NonNull final Activity activity) {
    final InputMethodManager iManager = (InputMethodManager) activity.
            getSystemService(Context.INPUT_METHOD_SERVICE);
    final View view = activity.getCurrentFocus();
    if (view != null && iManager != null) {
        iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
 
源代码21 项目: AndroidCommons   文件: KeyboardHelper.java
/**
 * Shows soft keyboard and requests focus for given view.
 */
public static void showSoftKeyboard(Context context, View view) {
    if (view == null) {
        return;
    }

    final InputMethodManager manager = (InputMethodManager)
            context.getSystemService(Context.INPUT_METHOD_SERVICE);
    view.requestFocus();
    manager.showSoftInput(view, 0);
}
 
源代码22 项目: MHViewer   文件: AppHelper.java
public static void hideSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
 
源代码23 项目: Social   文件: EaseChatPrimaryMenuBase.java
/**
 * 隐藏软键盘
 */
public void hideKeyboard() {
    if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
        if (activity.getCurrentFocus() != null)
            inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
源代码24 项目: caffeine   文件: ViewUtils.java
/**
 * Go away keyboard, nobody likes you.
 *
 * @param context The current Context or Activity that this method is called from.
 * @param field   field that holds the keyboard focus.
 */
public static void closeKeyboard(Context context, View field) {
    try {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(field.getWindowToken(), 0);
    } catch (Exception ex) {
        Log.e("Caffeine", "Error occurred trying to hide the keyboard.  Exception=" + ex);
    }
}
 
源代码25 项目: Kalle   文件: ActivitySource.java
@Override
void closeInputMethod() {
    Activity activity = getSource();
    View focusView = activity.getCurrentFocus();
    if (focusView != null) {
        InputMethodManager manager = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (manager != null) {
            manager.hideSoftInputFromWindow(focusView.getWindowToken(), 0);
        }
    }
}
 
源代码26 项目: FamilyChat   文件: DigitsEditText.java
@Override
public boolean onTouchEvent(MotionEvent event)
{
    final boolean ret = super.onTouchEvent(event);
    // Must be done after super.onTouchEvent()
    final InputMethodManager imm = ((InputMethodManager) getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE));
    if (imm != null && imm.isActive(this))
        imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
    return ret;
}
 
源代码27 项目: Simpler   文件: InputMethodUtils.java
/**
 * 为给定的编辑器开启软键盘
 *
 * @param editText 给定的编辑器
 */
public static void openSoftKeyboard(Context context, EditText editText) {
    editText.requestFocus();
    InputMethodManager inputMethodManager
            = (InputMethodManager) context.getSystemService(
            Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(editText,
            InputMethodManager.SHOW_IMPLICIT);
}
 
源代码28 项目: android-atleap   文件: SoftInputUtil.java
/**
 * Show keyboard
 * @param context context
 * @param view The currently focused view, which would like to receive
 * soft keyboard input.
 */
public static void showSoftInput(Context context, View view) {
    if (view == null)
        return;

    InputMethodManager inputMethodManager = (InputMethodManager)
            context.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(view, 0);
}
 
源代码29 项目: Android-Next   文件: AndroidUtils.java
public static void toggleSoftInput(Context context, View view) {
    if (view.requestFocus()) {
        InputMethodManager imm = (InputMethodManager)
                context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, 0);
    }
}
 
源代码30 项目: Kratos   文件: ActivityUtils.java
/**
 * 隐藏软键盘
 */
public static void showKeyboard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.
            getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    }
}
 
 类所在包
 同包方法