简体   繁体   English

为什么我的softKeyboard无法在android中自动显示

[英]Why isn't my softKeyboard coming up automatically in android

Strangely, my soft keyboard is not opening automatically.On SO I have looked they seem to ask on How to hide Keyboard...? 奇怪的是,我的软键盘没有自动打开。在我看来,他们似乎在问如何隐藏键盘...?

I would like to get the keyboard automatically focues on the Text Box. 我想自动将键盘放在文本框中。

Here is what I have on my XML 这是我在XML上拥有的

        android:id="@+id/msg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cursorVisible="true"
        android:gravity="left"
        android:imeOptions="actionDone"
        android:inputType="textMultiLine"
        android:maxLength="255"
        android:paddingLeft="5dp"
        android:scrollbars="vertical"
        android:textColor="#000000"
        android:textColorHint="#000000"
        android:textSize="25sp" />

How to fix this? 如何解决这个问题?

You stated "Text box".. If you meant "EditText" than one possibility will be to see if there is any other view that is requesting the focus. 您说了“文本框”。如果您要表示“ EditText”,则一种可能性是查看是否有其他视图请求焦点。 You can also try to add view.requestFocus programatically. 您也可以尝试以编程方式添加view.requestFocus。

I suppose you need add: 我想您需要添加:

android:textCursorDrawable="@null" 机器人:textCursorDrawable = “@空”

to EditText to see the cursor 到EditText看光标

Simply add this code <requestFocus /> To the EditText you want to be focused and it will open the keyboard for that field: 只需将此代码<requestFocus />添加到您要聚焦的EditText,它将打开该字段的键盘:

<EditText
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPassword" >

    <requestFocus />
</EditText> 

Add the following line inside your Activity tag in AndroidManifest.xml , AndroidManifest.xmlActivity标签内添加以下行,

android:windowSoftInputMode="stateAlwaysVisible"

Developer site says, 开发人员网站说,

"stateAlwaysVisible" : The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. “ stateAlwaysVisible”The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. 变为 The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

reference 参考

https://stackoverflow.com/a/1510005/1665507 https://stackoverflow.com/a/1510005/1665507

http://developer.android.com/guide/topics/manifest/activity-element.html http://developer.android.com/guide/topics/manifest/activity-element.html

http://blog.vogella.com/2010/10/25/android-windowsoftinputmode/ http://blog.vogella.com/2010/10/25/android-windowsoftinputmode/

why you have to open a keyboard on a code. 为什么必须在代码上打开键盘。 it will automatically get opened if you are on EditText 如果您在EditText上,它将自动打开

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM