android – 活动开始时不显示软键盘

android – 活动开始时不显示软键盘,第1张

概述我在 AndroidManifest.xml中的Activity中添加了android:windowSoftInputMode =“stateAlwaysVisible”,这是我的布局: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/and 我在 AndroidManifest.xml中的Activity中添加了androID:windowsoftinputMode =“statealwaysVisible”,这是我的布局:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical" androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent">    <EditText androID:ID="@+ID/EditText01" androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"></EditText>    <EditText androID:ID="@+ID/EditText02" androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"></EditText>    <button androID:ID="@+ID/button01" androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content" androID:text="Send"></button></linearLayout>

alt text http://img227.imageshack.us/img227/2006/18021414.png

当Activity启动时,EditText会聚焦,但不会显示软键盘.如果我点击EditText,那么我会看到软键盘.我的Activity启动时是否需要设置aditional参数来显示软键盘?

谢谢

解决方法 解决方案1:

在onCreate()方法的活动中写下面的代码

inputMethodManager imm = (inputMethodManager)    SearchActivity.this.getSystemService(Context.input_METHOD_SERVICE);if (imm != null){    imm.toggleSoftinput(inputMethodManager.SHOW_FORCED,0);}

解决方案2:

创建以下方法并从onCreate()调用

private voID showVirturalKeyboard(){    Timer timer = new Timer();    timer.schedule(new TimerTask() {         @OverrIDe         public voID run() {              inputMethodManager m = (inputMethodManager) SearchActivity.this.getSystemService(Context.input_METHOD_SERVICE);              if(m != null){                // m.toggleSoftinput(0,inputMethodManager.HIDE_NOT_ALWAYS);                m.toggleSoftinput(0,inputMethodManager.SHOW_IMPliCIT);              }          }    },100);         }
总结

以上是内存溢出为你收集整理的android – 活动开始时不显示软键盘全部内容,希望文章能够帮你解决android – 活动开始时不显示软键盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134906.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存