【发布时间】:2012-03-18 16:34:39
【问题描述】:
我想在Activity启动时打开软键盘,我发现
android:windowSoftInputMode="stateVisible"
没用。
为了确保,我创建了一个新项目(默认的“Hello world”)并执行了以下操作:
- 将 windowSoftInputMode 添加到清单中。
- 在那之后不起作用,我在布局中添加了一个 EditView 字段
- 后来不行,我加了
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
到 onCreate 过程。
我用 Android2.3.3 编译它并尝试在我的 Galaxy S2 设备和 Android4 模拟器上运行它 仍然 - 没有键盘。
我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="9" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".HelloworldActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateVisible">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我的 main.xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
我的代码:
public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
【问题讨论】:
-
我认为 'android:windowSoftInputMode' 是 'activity' 元素/标签属性。
-
你是对的 - 我改变了它。还是没有键盘。
-
你做了什么?终于解决了吗?
-
差不多 8 年前,但我看到这检查了 Muky 的答案。这可能是我使用的特定键盘的错误
标签: android android-layout android-emulator