設(shè)置/限制EditText只顯示一行
在Layout文件中,設(shè)置android:maxLines="1" 和 android:inputType="text"。
<EditText
android:id="@+id/searchbox"
android:maxLines="1"
android:inputType="text"
>
</EditText>
隱藏虛擬鍵盤
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
用代碼實(shí)現(xiàn)單擊按鈕
button.performClick()
如果單擊有動畫的話,每一步之后還需要button.invalidate
button.performClick();
button.setPressed(true);
button.invalidate();
button.setPressed(false);
button.invalidate();
焦點(diǎn)變化事件(尚未測試)
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();
}
}
});