Show / hide Soft Keyboard events in Android

I need to get Show / Hidden event from SoftKeyboard in Android.

I did a study, but nothing worked.

I wanted us to work with a 5.0 "low resolution tablet, so when you edit EditText, the keyboard goes up in full screen mode, and then either you press the enter or next key, or you press the back button to hide the keyboard ... I need to update some fields with a new value, but I cannot use TextWatcher because you have some business logic about which correct fields to update, and because I just want to update when the user really completes input.

And onFocusChanged is not an option, because we do not want our customers to need an attack in the next field and hide the keyboard to see the new values.

I also do not want to redefine onTouchEvent, look if the user is not the same field as the clicker that he is editing.

Sorry for the specific problem and more specific solution that I am asking for.

And sorry for my bad english: D

+1
source share
2 answers

Use the viewing tree observer to detect any changes in viewing height, and at this time you can check if the keyboard state is

final View activityRootView = findViewById(R.id.chat_pane_root_view); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { InputMethodManager mgr = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); if(mgr.isAcceptingText()) { //keyboard is up } } }); 
+4
source

First of all, in your statement about your activity in a manifest file declaration like this

 <activity android:name="Map" android:windowSoftInputMode="stateHidden"> 

your keyboard is hidden from this property, after that you declare the imeOption property in the main.xml edittext file like this

 <EditText android:id="@+id/edttexttitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:hint="@string/tasktitle" android:imeOptions="actionNext" android:inputType="text" android:textSize="@dimen/font_size_medium" android:textColor="@color/darkgray1" /> 

this code is for your first edittext, if more than one, and if only one edittext, then you need to change imeOption edittext, for example

 android:imeOptions="actionGo" 
-1
source

Source: https://habr.com/ru/post/1481400/


All Articles