阻止EditText弹出输入法
//EditText有焦点阻止输入法弹出
editText.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//记住EditText的InputType现在是password
int inType = editText.getInputType(); // backup the input type
editText.setInputType(InputType.TYPE_NULL); // disable soft input
editText.onTouchEvent(event); // call native handler
editText.setInputType(inType); // restore input type
editText.setSelection(editText.getText().length());
return true;
}
});
在Android系统中,由于手机屏幕大小的限制,一般需要字符输入的时候,弹出的输入法面板往往会占据大半个屏幕,如果输入框正好在下方,那经常会出现被输入法面板遮挡的尴尬,给使用者带来不小的困扰,用户体验很不友好。
查了一下Android SDK的说明,发现可以通过设置Activity的一个属性来解决这个问题,比如可以在AndroidManifest.xml中这样写:
< activity android:name=”.CategoryList”
android:label=”@string/app_name”
android:windowSoftInputMode=”stateVisible|adjustPan” >
< /activity >
这里面的android:windowSoftInputMode就是用来避免输入法面板遮挡问题的,具体的参数说明可参考SDK文档,但是,文档中说明,该属性是Android 1.5之后才加上的,也就是API Level 3以后的SDK才支持,那么如果在联想O1这样的机器上就不管用了,则该怎么办呢?好在我又找到了另外一种解决办法,就是ScrollView。我们可以在对应的layout XML的顶级元素上加一层ScrollView,这样,在这个ScrollView中,所有的文本框在输入法面板弹出的时候都会自动的向上滚动,示例代码如下:
< ScrollView xmlns:android=”[url]http://schemas.android.com/apk/res/android[/url] “
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
< LinearLayout android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
< EditText android:id=”@+id/content”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:lines=”4″
android:scrollbars=”vertical”
android:gravity=”fill_horizontal” / >
< /LinearLayout >
< /ScrollView >
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow