Android(安卓)Studio控件技巧汇总
16lz
2021-12-04
设置/限制EditText只显示一行
在Layout文件中,设置android:maxLines="1"
和 android:inputType="text"
。
隐藏虚拟键盘
View view = this.getCurrentFocus();if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0);}
参考:
https://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard
用代码实现单击按钮
button.performClick()
如果单击有动画的话,每一步之后还需要button.invalidate
button.performClick(); button.setPressed(true); button.invalidate(); button.setPressed(false); button.invalidate();
https://stackoverflow.com/questions/5701666/can-i-click-a-button-programmatically-for-a-predefined-intent
焦点变化事件(尚未测试)
editText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { Toast.makeText(getApplicationContext(), "Got the focus", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "Lost the focus", Toast.LENGTH_LONG).show(); } }});
更多相关文章
- Android(安卓)设置StatusBar的颜色
- Android全屏设置的两种方式
- android 设置系统屏幕亮度
- 2011.08.15(2)——— android audioManager解决MediaPlayer AudioT
- Android中贪吃蛇游戏的学习(三)
- android TextView ellipsize 只显示一个点 解决方案
- Android中设置分割线
- Android(安卓)欢迎界面设置
- AndroidManifest.xml - activity 详细说明