2011-08-22 32 views
0

這個例子看看:禁用,重新啓用和軟鍵盤不會出現在觸摸

public class TestEditSoftKbdActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    findViewById(R.id.editText1).setFocusable(false); 
    findViewById(R.id.editText1).setClickable(false); 
    findViewById(R.id.editText1).setEnabled(false); 

    findViewById(R.id.editText1).setFocusable(true); 
    findViewById(R.id.editText1).setClickable(true); 
    findViewById(R.id.editText1).setEnabled(true); 

    findViewById(R.id.editText1).invalidate(); 
    findViewById(R.id.editText1).requestLayout(); 
} 

}

這個順序調用的編輯文本視圖將不再彈出其軟後在輸入法被感動:(

有人能解釋這是怎麼回事?

+0

你爲什麼要膨脹8次? – Egor

+1

它可能是一些簡單的事情 - 嘗試設置啓用之前focusable - setFocusable完全可能不會在禁用視圖上執行任何操作。 – Delyan

+0

@Delyan - 很好的推理,+1。無論我如何重新排列它們,它都無濟於事 – kellogs

回答

0

如果你想關閉軟鍵盤爲您的文本視圖遵循this link。這是您的解決方案。但是你需要定義你自己的TextView來做到這一點。他建議使用;

public class NoImeEditText extends EditText { 
    public EditTextEx(Context context, AttributeSet attrs) { 
     super(context, attrs);  
    }  
    @Override  
    public boolean onCheckIsTextEditor() { 
     return false;  
    }   
} 

希望它有效。