简体   繁体   English

屏幕打开时如何自动显示android键盘?

[英]how to show android Keyboard automatically while Screen Opens?

Can anyone tell me how to show the soft input keyboard while a activity opens. 有人可以告诉我如何在活动打开时显示软输入键盘。 In Normal case a keyboard pops up when we tap inside the edit text but i want to open it automatically when that screen loads. 在正常情况下,当我们在编辑文本中点击时会弹出一个键盘,但是我想在屏幕加载时自动将其打开。

here is the xml layout file 这是xml布局文件

and here is the main.xml layout file 这是main.xml布局文件

<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="This is my sample App of android"
    android:textColor="#000000" android:textSize="20dip">

</TextView>

<EditText android:id="@+id/EditText01" android:layout_height="wrap_content"
    android:layout_width="fill_parent"></EditText>

<Button android:id="@+id/Button01" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Say Hello"></Button>

Check android:windowSoftInputMode attribute for activity element of AndroidManifest.xml. android:windowSoftInputMode属性中检查AndroidManifest.xml的activity元素。 In your case it could be: 在您的情况下,可能是:

<activity android:windowSoftInputMode="stateAlwaysVisible" ... />
<activity android:windowSoftInputMode="stateAlwaysVisible" ... />

as Ralkie's answer. 作为罗基的答案。 But to test on emulator you have to be careful in how your AVD is configured: the default configuration has keyboard support... You need to add the hardware property "Keyboard support" with "no" value on your AVD in order to test it on emulator. 但是要在仿真器上进行测试,您必须谨慎配置AVD:默认配置具有键盘支持...您需要在AVD上添加硬件属性“ Keyboard support”(键盘支持),其值为“ no”,以便对其进行测试在模拟器上。

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

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