the editText is not losing focus in my app when I click out of it, it has the orange border all time and that black line cursor.. I did this a LinearLayout according to this surrounding the editText: Stop EditText from gaining focus at Activity startup so it doesn't get focus on start of the app..
this is my code:
final EditText et = (EditText)findViewById(R.id.EditText01);
final InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
et.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
}
});
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasfocus) {
if(hasfocus) {
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
} else {
imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
}
}
});
But, it doesn't seem to be calling the onFocusChange when I click anywhere outside the editText!
You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts. The .... is just saying that you can put it anywhere else in the class.
It's simple. You can put the following in LinearLayout or any other else:
android:focusableInTouchMode="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With