从EDITTEXT在对话框中删除焦点时,键盘下跌 [英] Remove focus from editText in dialog when keyboard is down

查看:191
本文介绍了从EDITTEXT在对话框中删除焦点时,键盘下跌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AlertDialog在它的编辑文本。当你点击后退键,键盘下降(因为它应该),但编辑文本仍然是关注的焦点。如果你再次点击返回键,整个对话框消失。

I have an AlertDialog with an edit text in it. When you hit the back key, the keyboard goes down (as it should), but the edit text is still with focus. If you hit the back key again, the whole dialog disappears.

我想在隐藏键盘,除去从对话框内编辑文本的焦点,但无法弄清楚如何。

I want to remove the focus from the edit text inside the dialog upon hiding the keyboard, but can't figure out how to.

请注意,我不希望覆盖pssed的onBack $ P $或类似的东西,因为我只是想控制时会发生什么后退按钮是pressed当对话框了。

Note that I don't want to override the onBackPressed or something similar, because I just want to control what happens when the back button is pressed when the dialog is up.

任何想法?

推荐答案

我的问题的解决方案是部分为@ kabuto178说 - 我用一个聚焦的的FrameLayout 父我的的EditText ,并呼吁然后在 edittext.clearFocus()击中后,返回键,家长的FrameLayout上涨焦点:

The solution to my problem was partially as @kabuto178 said - I used a focusable frameLayout as the parent of my EditText, and then when called the edittext.clearFocus() upon hitting the back key, the parent frameLayout gained the focus:

final FrameLayout parent = new FrameLayout(context);
final EditText v = new EditText(context);
parent.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));
parent.addView(v);
parent.setFocusableInTouchMode(true);
v.requestFocus();

这篇关于从EDITTEXT在对话框中删除焦点时,键盘下跌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆