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 edittexts) , 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -