扫码关注官方订阅号
本来有个editText,然后编辑的时候这个键盘会出来,我想自己设置一个按钮,然后隐藏键盘。
学习是最好的投资!
使用InputMethodManager即可。
主要代码如下(亲测可用,仅供参考):
public class MainActivity extends Activity { private Boolean isShow = false ; EditText editText; InputMethodManager imm; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = (EditText) findViewById(R.id.editText); imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); Button showHideBtn = (Button) findViewById(R.id.show_hide_btn); showHideBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (isShow) { isShow = false; imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); } else { isShow = true; imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); } } }); } }
官方文档如下:http://developer.android.com/referenc...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用InputMethodManager即可。
主要代码如下(亲测可用,仅供参考):
官方文档如下:http://developer.android.com/referenc...