---
title: "ActivityGroup与EditText焦点问题"
author: "phenom"
date: "2011-12-06T10:34:42Z"
tags: []
categories: ["移动开发"]
slug: "activitygroup-edittext"
draft: false
lastmod: "2011-12-06T10:34:42Z"
id: 1293411
url: "https://phenom.iteye.com/blog/1293411"
---

tab用了ActivityGroup来处理，因为工程是前面人留下的，没有修改tab了，然后里面的EditText就一直是焦点状态，键盘处理弹出状态。

boolean flag=imm.hideSoftInputFromWindow(mSearch.getWindowToken(),InputMethodManager.RESULT_HIDDEN);
        Log.d(TAG,"flag:"+flag);

        flag=imm.hideSoftInputFromWindow(mSearch.getWindowToken(),InputMethodManager.RESULT_UNCHANGED_HIDDEN);
        Log.d(TAG,"flag:"+flag);

        flag=imm.hideSoftInputFromWindow(mSearch.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
        Log.d(TAG,"flag:"+flag);

        flag=imm.hideSoftInputFromWindow(mSearch.getWindowToken(),InputMethodManager.HIDE_IMPLICIT_ONLY);
        Log.d(TAG,"flag:"+flag);
这些不可控制，也是非常无语啊，在androidmanifest里面再配置同样无效。不知道这是什么问题，后来才知道。mSearch.getWindowToken()这个为null,
然后就无法获取imm，所以无法关闭。也没找到AttachInfo为什么没有初始化。

有人说mSearch.clearFocus()之类的方法可以，试 了，同样无效。快绝望时，突然把ET设为android:editable="false" ，键盘不会再弹出来了。这也是目前我找到的唯一可用办法。

你也许会问题，如果不可编辑，如何输入文字呢？可以这样处理。在它前面加一个<EditText
            android:lines="1" android:editable="false" 
            android:layout_margin="0dip"
            android:layout_width="0dip" android:layout_height="0dip"/>
这样就可以了。当然，此时mSearch也不会有光标闪烁，世界安静了。