阻止EditText弹出输入法

               

阻止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.csdn.net/jiangjunshow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值