当前位置: 代码迷 >> Android >> 关于edittext获得焦点有关问题
  详细解决方案

关于edittext获得焦点有关问题

热度:64   发布时间:2016-04-27 22:55:49.0
关于edittext获得焦点问题
本来控件正常显示的,后来客户要求进入画面后,控件直接显示光标,但是不自动弹出输入法,点击控件才会弹出输入法。
我修改了下,自动显示光标也就是获得焦点并且没有自动弹出输入法成功了,但是出现了问题,点击控件不会弹出输入法,请教为什么。我试过两种方法,结果都是一样

---------------------------------------------------------第一种更改java代码----------------
mEditText = (EditText)findViewById(R.id.et_input); 
        btnClear = (ImageButton)findViewById(R.id.ib_clear);  
        mEditText.setFocusable(true);
        mEditText.setFocusableInTouchMode(true);
        mEditText.requestFocus();


--------------------------------------------------------------------------第二种- xml文件------
 <EditText
        android:id="@+id/et_input"
        android:layout_width="fill_parent"
        android:layout_height="45px"
android:background="#00000000"
        android:hint="输入首字母或名称"
        android:maxLength="14"
        android:imeOptions="actionSearch"
        android:paddingLeft="15px"
        android:paddingRight="15px"
        android:singleLine="true"
        android:gravity="center_vertical|left"
        android:textColor="@color/app_white"
        android:textSize="@dimen/font_26"
        android:textColorHint="@color/app_gray"> 
         <requestFocus />  </EditText>
------解决思路----------------------
引用:
Quote: 引用:

把  <requestFocus />去掉,加上android:textCursorDrawable="@null"这句。

没有用啊
这只是让你获取焦点,你要控制键盘当然还要在代码里控制。
public void cancleKeyBoard() {
View view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

public void showKeyBoard(){
int STATE_VISIBLE=WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
int ADJUST_RESIZE=WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
getWindow().setSoftInputMode(STATE_VISIBLE
------解决思路----------------------
ADJUST_RESIZE);
}
这是控制键盘弹出与隐藏的方法。
------解决思路----------------------
引用:
Quote: 引用:

你就写个简单的EditText 你看看会不会弹出对话框

当然可以啊。
1:进入画面自动获得焦点并且没有自动弹出输入法。
2:点击控件弹出输入法;
问题是1实现了,2不能实现了。

那就有可能是你的输入法问题了-

楼上的 方法也行  比较直接--