android.view.inputmethod.InputMethodManager#toggleSoftInput ( )源码实例Demo

下面列出了android.view.inputmethod.InputMethodManager#toggleSoftInput ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: iBeebo   文件: AbstractWriteActivity.java
@Override
public void onBackPressed() {
    if (smiley.isShown()) {
        removeViewWithAnim(smiley);
    } else if (!TextUtils.isEmpty(et.getText().toString()) && canShowSaveDraftDialog()) {
        SaveDraftDialog dialog = new SaveDraftDialog();
        dialog.show(getFragmentManager(), "");
    } else {

        if (BeeboApplication.getInstance().getAccountBean().equals(getCurrentAccountBean())) {
            super.onBackPressed();
        } else {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm.isActive()) {
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
            }
            Intent intent = MainTimeLineActivity.newIntent(getCurrentAccountBean());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

    }
}
 
源代码2 项目: Infinity-For-Reddit   文件: SearchActivity.java
@Override
protected void onStart() {
    super.onStart();
    simpleSearchView.showSearch(false);
    simpleSearchView.getSearchEditText().requestFocus();

    if (query != null) {
        simpleSearchView.getSearchEditText().setText(query);
        simpleSearchView.getSearchEditText().setSelection(query.length());
        query = null;
    }

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
}
 
源代码3 项目: NIM_Android_UIKit   文件: TFragment.java
protected void showKeyboard(boolean isShow) {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }

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

    if (isShow) {
        if (activity.getCurrentFocus() == null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {
            imm.showSoftInput(activity.getCurrentFocus(), 0);
        }
    } else {
        if (activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }

    }
}
 
源代码4 项目: Ticket-Analysis   文件: KeyboardUtils.java
/**
 * 切换键盘显示与否状态
 */
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);
}
 
源代码5 项目: deltachat-android   文件: HiddenEditText.java
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
  boolean focus = super.requestFocus(direction, previouslyFocusedRect);

  if (currentTextEntity != null && focus) {
    currentTextEntity.setFocused(true);
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
    if (!imm.isAcceptingText()) {
      imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
  }

  return focus;
}
 
源代码6 项目: Yuan-SxMusic   文件: CommonUtil.java
/**
 * EditText获取焦点并显示软键盘
 */
//弹出软键盘
public static void showKeyboard(EditText editText, Context context) {
    //其中editText为dialog中的输入框的 EditText
    if (editText != null) {
        //设置可获得焦点
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        //请求获得焦点
        editText.requestFocus();
        //调用系统输入法
        InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
源代码7 项目: CustomSearchView   文件: SearchView.java
/**
 * 通知监听者 进行搜索操作
 * @param text
 */
private void notifyStartSearching(String text){
    if (mListener != null) {
        mListener.onSearch(etInput.getText().toString());
    }
    //隐藏软键盘
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
源代码8 项目: DevUtils   文件: KeyBoardUtils.java
/**
 * 打开软键盘
 * @param editText {@link EditText}
 * @return {@code true} success, {@code false} fail
 */
public static boolean openKeyboard(final EditText editText) {
    if (editText != null) {
        try {
            InputMethodManager imm = AppUtils.getInputMethodManager();
            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            return true;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "openKeyboard");
        }
    }
    return false;
}
 
源代码9 项目: o2oa   文件: UIView.java
protected void showKeyboard(boolean isShow) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (isShow) {
        if (getCurrentFocus() == null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {
            imm.showSoftInput(getCurrentFocus(), 0);
        }
    } else {
        if (getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
 
源代码10 项目: bitseal   文件: SecurityActivity.java
/**
 * If the soft keyboard is open, this method will close it. Currently only
 * works for API 16 and above. 
 */
private void closeKeyboardIfOpen()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		final View activityRootView = getWindow().getDecorView().getRootView();	
		final OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener()
		{
			@Override
			@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
			public void onGlobalLayout() 
			{
			    Rect rect = new Rect();
			    // rect will be populated with the coordinates of your view that area still visible.
			    activityRootView.getWindowVisibleDisplayFrame(rect);

			    int heightDiff = activityRootView.getRootView().getHeight() - (rect.bottom - rect.top);
			    if (heightDiff > 100)
			    {
			    	// If the difference is more than 100 pixels, it's probably caused by the soft keyboard being open. Now we want to close it.
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // Toggle the soft keyboard. 
			    }
			    
			    // Now we have to remove the OnGlobalLayoutListener, otherwise we will experience errors
			    activityRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}
		};
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
	}
}
 
源代码11 项目: AndroidStudyDemo   文件: DisplayUtil.java
/**
 * Toggle keyboard If the keyboard is visible,then hidden it,if it's
 * invisible,then show it
 *
 * @param context 上下文
 */
public static void toggleKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive()) {
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
源代码12 项目: bitseal   文件: NetworkSettingsActivity.java
/**
 * If the soft keyboard is open, this method will close it. Currently only
 * works for API 16 and above. 
 */
private void closeKeyboardIfOpen()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		final View activityRootView = getWindow().getDecorView().getRootView();	
		final OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener()
		{
			@Override
			@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
			public void onGlobalLayout() 
			{
			    Rect rect = new Rect();
			    // rect will be populated with the coordinates of your view that area still visible.
			    activityRootView.getWindowVisibleDisplayFrame(rect);

			    int heightDiff = activityRootView.getRootView().getHeight() - (rect.bottom - rect.top);
			    if (heightDiff > 100)
			    {
			    	// If the difference is more than 100 pixels, it's probably caused by the soft keyboard being open. Now we want to close it.
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // Toggle the soft keyboard. 
			    }
			    
			    // Now we have to remove the OnGlobalLayoutListener, otherwise we will experience errors
			    activityRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}
		};
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
	}
}
 
源代码13 项目: Infinity-For-Reddit   文件: EditPostActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    ((Infinity) getApplication()).getAppComponent().inject(this);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_edit_post);

    ButterKnife.bind(this);

    EventBus.getDefault().register(this);

    applyCustomTheme();

    if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
        Slidr.attach(this);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
        addOnOffsetChangedListener(appBarLayout);
    }

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
    mAccessToken = getIntent().getStringExtra(EXTRA_ACCESS_TOKEN);
    titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE));
    mPostContent = getIntent().getStringExtra(EXTRA_CONTENT);
    contentEditText.setText(mPostContent);

    contentEditText.requestFocus();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
}
 
源代码14 项目: ResearchStack   文件: ViewTaskActivity.java
private void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (imm.isActive() && imm.isAcceptingText()) {
        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    }
}
 
源代码15 项目: zone-sdk   文件: KeyBoardUtils.java
/**
 * 如果输入法已经显示,那么就隐藏它;如果输入法现在没显示,那么就显示它
 */
public static void toggle(Context context) {
	InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
	imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
源代码16 项目: CoolChat   文件: KeyboardUtils.java
/**
 * 开关输入法
 *
 * @param currentFocusView 当前焦点view
 */
public static void toggleSoftInput(View currentFocusView) {
    InputMethodManager imm = (InputMethodManager) currentFocusView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(currentFocusView, InputMethodManager.RESULT_SHOWN);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
源代码17 项目: android-common   文件: InputMethodUtils.java
public static void toggleSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
public static void toggleSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
 
源代码19 项目: BaseProject   文件: BaseUiHelper.java
public static void toggleSoftInput(Context context) {
    InputMethodManager inputmanger = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputmanger != null) {
        inputmanger.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS );
    }
}
 
源代码20 项目: quickhybrid-android   文件: DeviceUtil.java
/**
 * 控制键盘显隐,如果输入法在窗口上已经显示,则隐藏,反之则显示
 *
 * @param context
 */
public static void toggleInputKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}