@Override public void onClick(View v) { InputMethodManager m = (InputMethodManager) mNewsReplyEditText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); // TODO Auto-generated method stub switch (v.getId()) { // 图片按钮 case R.id.news_reply_img_btn: mNewsReplyEditLayout.setVisibility(View.VISIBLE); mNewsReplyImgLayout.setVisibility(View.GONE); mNewsReplyEditText.requestFocus(); // 显示输入法 m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT); break; // 发送按钮 case R.id.news_reply_post: // 隐藏输入法 m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); String str = mNewsReplyEditText.getText().toString(); if (str.equals("")) { Toast.makeText(CommentsActivity.this, "不能为空", Toast.LENGTH_SHORT).show(); } else { mNewsReplyEditLayout.post( new PostCommentsThread(mNid, "广州市", str + "", new NewsDetailActivity())); mNewsReplyEditLayout.setVisibility(View.GONE); mNewsReplyImgLayout.setVisibility(View.VISIBLE); } break; } }
/** 处理NewsDetailsTitleBar点击事件 */ @Override public void onClick(View v) { InputMethodManager m = (InputMethodManager) mNewsReplyContent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); switch (v.getId()) { // 上一条新闻 case R.id.newsdetails_titlebar_previous: if (mPosition > 0) { detailViewPager.setCurrentItem(mPosition - 1); } else { Toast.makeText(this, "没有上条新闻", Toast.LENGTH_SHORT).show(); } break; // 下一条新闻 case R.id.newsdetails_titlebar_next: if (mPosition < mNewsData.size() - 1) { detailViewPager.setCurrentItem(mPosition + 1); } else { Toast.makeText(this, "没有下条新闻", Toast.LENGTH_SHORT).show(); } break; // 显示评论 case R.id.newsdetails_titlebar_comments: Intent intent = new Intent(NewsDetailsActivity.this, CommentsActivity.class); // 传递新闻ID intent.putExtra("nid", mNid); startActivity(intent); break; // 新闻回复图片 case R.id.news_reply_img_btn: mNewsReplyImgLayout.setVisibility(View.GONE); mNewsReplyEditLayout.setVisibility(View.VISIBLE); mNewsReplyContent.requestFocus(); // 使输入框聚焦 m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT); break; // 发表新闻回复 case R.id.news_reply_post: new PostCommentThread().start(); mNewsReplyImgLayout.setVisibility(View.VISIBLE); mNewsReplyEditLayout.setVisibility(View.GONE); m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); break; case R.id.news_share_btn: // 设置分享新闻 Intent intent2 = new Intent(Intent.ACTION_SEND); intent2.setType("image/*"); intent2.putExtra(Intent.EXTRA_TEXT, "来自展鸿新闻客户端:" + newslist_item_title); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent2, getTitle())); break; case R.id.tap_back: mNewsReplyImgLayout.setVisibility(View.VISIBLE); mNewsReplyEditLayout.setVisibility(View.GONE); break; } }
public void toggleInput() { if (context != null) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case android.R.id.home: savaDraft(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); intent = new Intent(this, MainTimeLineActivity.class); intent.putExtra("account", getAccount()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); break; case R.id.menu_emoticon: EmotionsGridDialog dialog = new EmotionsGridDialog(); dialog.show(getFragmentManager(), ""); break; case R.id.menu_topic: String ori = content.getText().toString(); String topicTag = "##"; content.setText(ori + topicTag); content.setSelection(content.getText().toString().length() - 1); break; case R.id.menu_at: intent = new Intent(WriteWeiboActivity.this, AtUserActivity.class); intent.putExtra("token", token); startActivityForResult(intent, AT_USER); break; } return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); finish(); break; case R.id.menu_enable_ori_comment: if (enableCommentOri.isChecked()) { enableCommentOri.setChecked(false); } else { enableCommentOri.setChecked(true); } break; case R.id.menu_enable_repost: if (enableRepost.isChecked()) { enableRepost.setChecked(false); } else { enableRepost.setChecked(true); } break; case R.id.menu_at: Intent intent = new Intent(WriteCommentActivity.this, AtUserActivity.class); intent.putExtra("token", token); startActivityForResult(intent, AT_USER); break; } return true; }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.home: InfoSearchActivity.this.finish(); break; case R.id.zjzx_zixun: intent = new Intent(this, InformationMainActivity.class); startActivity(intent); break; case R.id.info_search_button: if (searchEdittext.getText().toString().equals("")) { Toast.makeText(InfoSearchActivity.this, "搜索内容不能为空", Toast.LENGTH_LONG).show(); } else { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 } imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); refreshListData(); } break; } }
private void initilizeViewVariables() { clearDescriptionButton = (Button) findViewById(R.id.descriptionCLRbtn); clearTitleButton = (Button) findViewById(R.id.titleCLRbtn); notifySwitch = (Switch) findViewById(R.id.switchNotificationLO); repeatSpinner = (Spinner) findViewById(R.id.spinnerRepeatingLO); timepicker = (TimePicker) findViewById(R.id.timePickerLO); datepicker = (DatePicker) findViewById(R.id.datePickerLO); timepicker.setIs24HourView(true); titleInputext = (EditText) findViewById(R.id.TitleEditTextLO); titleInputext.requestFocus(); descriptionInputText = (EditText) findViewById(R.id.descriptionEditTextLO); repeatAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.repeatArray)); repeatSpinner.setAdapter(repeatAdapter); clearDescriptionButton.setOnClickListener(this); clearTitleButton.setOnClickListener(this); drawer.setOnOpenListener(this); drawer.setOnCloseListener(this); notifySwitch.setOnCheckedChangeListener(this); initilizeVariables(); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } }
public static void showKeyboard(Activity activity) { InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (inputManager != null) { inputManager.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT); } }
public void hideSoftwareKeyboard() { if (softwareKeyboardIsVisible) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, 0); } softwareKeyboardIsVisible = false; }
public void openSoftKeyboard() { inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); Log.i(getClass().getSimpleName(), "Open Soft Keyboard"); } }
/** 显示或隐藏输入法 */ protected void toggleInput() { if (getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { if (inputMethodManager == null) inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }
/** Show the soft keyboard and store the view that triggered it */ private void showSoftKeyboard(View triggerView) { if (Log.DEBUG) Log.v("showSoftKeyboard()"); if (inputManager == null) { inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } inputView = triggerView; inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }
public void onClick(View view) { inputUrl.setVisibility(View.VISIBLE); inputUrl.requestFocus(); InputMethodManager imm = (InputMethodManager) NewMapActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput( InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); }
/* * 关闭键盘 */ public static void closeKeyBoard(Context context) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } }
public void showKeyboardAndFocusOnEditText() { if (getActivity() != null) { isKeyboardHidden = false; editText.requestFocus(); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }
/** * Shows the keyboard. * * @param context */ public static void show(Context context) { if (context != null) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); } else { Log.w(TAG, "show called with null context: " + context); } }
/** 登陆到主界面 */ @OnClick(R.id.btn_login) void onLogin() { // 隐藏软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); if (TextUtils.isEmpty(etUsername.getText().toString()) || TextUtils.isEmpty(etPassword.getText().toString())) { Snackbar.make(clContainer, "少年呦 你是忘记写账号了还是密码呢?", Snackbar.LENGTH_LONG).show(); } else { String username = etUsername.getText().toString(); String password = etPassword.getText().toString(); // 检测账号密码是否合法 if (StringUtil.checkString(username) && StringUtil.checkString(password)) { Map<String, String> params = new HashMap<String, String>(2); params.put(StringConstant.USER_NAME, username); params.put(StringConstant.USER_PWD, password); RequestInfo info = new RequestInfo(StringConstant.SERVER_LOGIN_URL, params); httpTools.post( info, new HttpCallback() { @Override public void onStart() {} @Override public void onFinish() {} @Override public void onResult(String s) { // 服务端返回Json System.out.println(s); if ("null".equals(s)) { Snackbar.make(clContainer, "少年呦 账号或密码不对", Snackbar.LENGTH_LONG).show(); return; } onReadJson(s); } @Override public void onError(Exception e) {} @Override public void onCancelled() {} @Override public void onLoading(long l, long l1) {} }); } else { Snackbar.make(clContainer, "少年呦 账号和密码要符合长度要求呦", Snackbar.LENGTH_SHORT).show(); } } // startActivity(new Intent(LoginActivity.this, MainActivity.class)); }
private void hideKeyboard() { if (getActivity() == null) { return; } InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }
@Override public void setMenuVisibility(boolean menuVisible) { super.setMenuVisibility(menuVisible); if (step == BATTERY_DATE) { cycles.requestFocus(); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }
private void doToggleSoftKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); termOut.setFocusable(false); prompt_box.setFocusableInTouchMode(true); prompt_box.setFocusable(true); prompt_box.requestFocus(); prompt_box.setSelection(prompt_box.getText().length()); }
// 打开虚拟键盘 public static void openSoftInput(Context context, View v) { if (v == null) { return; } InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED); imm.showSoftInput(v, 0); // imm.showSoftInputFromInputMethod(v.getWindowToken(), 0); }
@Override public void comment() { mCommentView.setVisibility(View.VISIBLE); editText.requestFocus(); imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); editText.getText().toString(); // getPosition(mListView); }
/** * 控制表情区和软键盘的显示 * * @param isShowKeyboard * @param isSwitch */ private void controlKeyboardOrExpr(boolean isShowKeyboard, boolean isSwitch) { if (isSwitch) { if (!isShowKeyboard) { mIsExprShow = true; mIsSoftKeyboardShow = false; mImm.hideSoftInputFromWindow(editText.getWindowToken(), 0); mUiHandler.postDelayed( new Runnable() { @Override public void run() { mExpressionWidgt.setVisibility(View.VISIBLE); } }, 100); mExprBtn.setBackgroundResource(R.drawable.selector_s_chat_keyboard); } else { mIsExprShow = false; mIsSoftKeyboardShow = true; mExpressionWidgt.setVisibility(View.GONE); mExprBtn.setBackgroundResource(R.drawable.selector_s_chat_expressions); mImm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } } else { if (isShowKeyboard) { mIsExprShow = false; mIsSoftKeyboardShow = true; mExpressionWidgt.setVisibility(View.GONE); mImm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } else { if (mIsSoftKeyboardShow) { mIsSoftKeyboardShow = false; mImm.hideSoftInputFromWindow(editText.getWindowToken(), 0); } else { mIsExprShow = false; mExpressionWidgt.setVisibility(View.GONE); } } mExprBtn.setBackgroundResource(R.drawable.selector_s_chat_expressions); } }
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_edit, container, false); editText = (EditText) view.findViewById(R.id.memo_edit); editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(getActivity().INPUT_METHOD_SERVICE); inputManager.toggleSoftInput(0, inputManager.SHOW_FORCED); // fragmentManager=getFragmentManager(); // // editText=(EditText)view.findViewById(R.id.memo_edit_edittext); // editText.setVisibility(View.GONE); // textView=(TextView)view.findViewById(R.id.memo_null_textview); // textView.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Memo_Choose_Fragment memo_choose_fragment= (Memo_Choose_Fragment) // fragmentManager.findFragmentByTag("choose"); // FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction(); // fragmentTransaction.remove(memo_choose_fragment); // fragmentTransaction.commit(); // } // }); // // deleteBT=(Button)view.findViewById(R.id.memo_delete_button); // // editBT=(Button)view.findViewById(R.id.memo_edit_button); // editBT.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // textView.setVisibility(View.GONE); // editText.setVisibility(View.VISIBLE); // editText.setFocusable(true); // editText.setFocusableInTouchMode(true); // editText.requestFocus(); // editBT.setVisibility(View.GONE); // deleteBT.setVisibility(View.GONE); // InputMethodManager inputManager // =(InputMethodManager)editText.getContext().getSystemService(getActivity().INPUT_METHOD_SERVICE); // inputManager.toggleSoftInput(0, inputManager.SHOW_FORCED); // } // }); return view; }
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { flag = false; System.out.println(position); superId = list.get(position - 1).getCommentId(); contentEdit.setHint("回复" + list.get(position - 1).getUserName() + ":"); discussBtn.setText("回复"); contentEdit.setFocusable(true); contentEdit.setFocusableInTouchMode(true); contentEdit.requestFocus(); imm.showSoftInputFromInputMethod(contentEdit.getWindowToken(), 0); imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.moblie_rechange_back_success, container, false); // ListView mListView = // (ListView)view.findViewById(R.id.result_listview); initResult(view); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, 0); return view; }
public void onFocusChange(View view, boolean flag) { InputMethodManager inputmethodmanager = (InputMethodManager)a.getSystemService("input_method"); if (flag) { a.e.setChecked(true); inputmethodmanager.toggleSoftInput(1, 0); return; } else { inputmethodmanager.hideSoftInputFromWindow(view.getWindowToken(), 0); return; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_item); Todo todo = (Todo) getIntent().getExtras().getSerializable("todo"); String text = todo.getValue(); priority = todo.getPriority(); date = todo.getDate(); ((TextView) findViewById(R.id.dateText)).setText(date); DialogFragment newFragment = new DatePickerFragmentForEdit(); newFragment.show(getSupportFragmentManager(), "datePicker"); position = getIntent().getIntExtra("position", 0); id = getIntent().getIntExtra("id", 0); et = (EditText) findViewById(R.id.as_name); et.setText(text); et.setSelection(text.length()); // priority as_switch = (Switch) findViewById(R.id.as_switch); if (priority.equals("LOW")) { as_switch.setChecked(false); } else { as_switch.setChecked(true); } // attach a listener to check for changes in state as_switch.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { priority = "HIGH"; } } }); // setting up the focus et.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); }
@Override protected void onRestart() { mAdapter.notifyDataSetChanged(); // 关闭软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); // 关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的 } robotName = MyApplication.getString(HttpUtils.ROBOT_NIKE_NAME, "小黄鸭"); title.setText(robotName); str = "您还记得大明湖畔的" + robotName + "吗?就是我喽," + "人称江湖百晓生,熟知段子、新闻、天气、列车、菜谱、航班、百度百科,很高兴为您服务!"; mAdapter.changeFirstItem(str); super.onRestart(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 29 && resultCode == Constants.MESSAGE_REPLY) { if (data != null && data.hasExtra("REPLY_NAME") && data.hasExtra("REPLY_ID")) { String id = data.getStringExtra("REPLY_ID"); String name = data.getStringExtra("REPLY_NAME"); TextInputProvider textInputProvider = (TextInputProvider) RongContext.getInstance().getPrimaryInputProvider(); textInputProvider.setEditTextContent(mEditText + name + " "); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } } }