我创建了一个简单的应用程序来测试以下功能.当我的活动启动时,需要在软键盘打开的情况下启动它.
我的代码不起作用?!
我已经在清单中尝试了各种"状态"设置,并且在InputMethodManager(imm)的代码中尝试了不同的标志.
我已将该设置包含在AndroidManifest.xml中,并在唯一活动的onCreate中显式调用.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.android.studyIme"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".StudyImeActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
...主要布局(main.xml)......
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/edit_sample_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hello"
android:inputType="textShortMessage"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
......和代码......
public class StudyImeActivity extends Activity {
private EditText mEditTextStudy;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud)