简体   繁体   English

在Android中显示/隐藏软键盘事件

[英]Show/Hidden Soft Keyboard event in Android

I need to get the Show/Hidden event from the SoftKeyboard in Android. 我需要从Android的SoftKeyboard获取Show / Hidden事件。

I did a research, but nothing worked. 我做了一项研究,但没有任何效果。

I wanted that 'cause we're working with a tablet 5.0'' with low resolution, so when you edit a EditText, the keyboard rise in full screen, and then or you press the "enter or next" key, or you press the back button to hide the keyboard... I need to update some fields with the new value, but I can't use the TextWatcher 'cause have some business logics on what's the right fields to update, and 'cause I just want to update when the user really finish the input. 我想要那个'因为我们正在使用低分辨率的平板电脑5.0',所以当你编辑EditText时,键盘会全屏显示,然后你按下“输入或下一个”键,或者按下后退按钮隐藏键盘...我需要用新值更新一些字段,但我不能使用TextWatcher'因为有一些业务逻辑什么是正确的字段要更新,'因为我只是想更新当用户真正完成输入时。

And the onFocusChanged isn't a option, 'cause we don't want our customers needing to cliking in the next field, and hiding the keyboard to see the new values. 并且onFocusChanged不是一个选项,因为我们不希望我们的客户需要在下一个字段中占用,并隐藏键盘以查看新值。

I don't want to override the onTouchEvent too, see if where the user cliked isn't the same field that he is editing. 我也不想覆盖onTouchEvent,看看用户cliked的位置与他正在编辑的字段不同。

Sorry for the specific problem and more specific solution that I'm asking for. 对不起我要求的具体问题和更具体的解决方案。

And sorry for my bad English :D 抱歉我的英语不好:D

Use tree view observer to detect any change in view height and that time you can check whether keyboard state 使用树形视图观察器来检测视图高度的任何变化,并且可以检查键盘状态

                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
                        }
                    }
                });

First of all in your declairation of your activity in manifest file declaire like this 首先,您在清单文件中声明您的活动声明如下

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

from this property your keyboard is being hidden, after this you are declaire the imeOption property in your main.xml file edittext like this 从这个属性你的键盘被隐藏,在此之后,你在main.xml文件edittext中声明了imeOption属性,就像这样

<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 then one and if only one edittext then your need to change the imeOption of edittext like 这个代码是第一个edittext,如果多于一个,如果只有一个edittext那么你需要更改edittext的imeOption

android:imeOptions="actionGo"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM