android - Hide soft keyboard on pressing back -
i have edittext
in activity
, want active , soft-keyboard open when open activity
. here xml
edittext
:
<edittext android:background="@null" android:cursorvisible="true" android:eleganttextheight="true" android:enabled="true" android:focusable="true" android:hint="search" android:id="@+id/edittext11" android:inputtype="textnosuggestions|textcapsentences" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_width="match_parent" android:singleline="true" android:textcolor="#000000" android:textcursordrawable="@null" />
and have used android:windowsoftinputmode="statevisible"
activity in have edittext
.
the problem is, when press back
once, keyboard not hide(ideally in other edittext
s) , when press back
again, closes activity
. on first back
press, not getting call onbackpressed()
while on second back
press, do. why kind of behaviour happening , how resolve it?
edit want is, if keyboard open, pressing should close keyboard , if keyboard not open, close activity.
try ...
create class called util , put code
public static void hidesoftkeyboard(activity activity) { final inputmethodmanager inputmethodmanager = (inputmethodmanager) activity.getsystemservice(activity.input_method_service); if (inputmethodmanager.isactive()) { if (activity.getcurrentfocus() != null) { inputmethodmanager.hidesoftinputfromwindow(activity.getcurrentfocus().getwindowtoken(), 0); } } }
and call on onbackpressed() of activity
Comments
Post a Comment