android:windowSoftInputMode ="stateVisible"不起作用

Asa*_*ssi 9 android android-emulator android-layout

我想在Activity开始时打开软键盘,我发现了

android:windowSoftInputMode="stateVisible" 
Run Code Online (Sandbox Code Playgroud)

不起作用.

为了确保,我创建了一个新项目(默认的"Hello world")并执行了以下操作:

  1. 将windowSoftInputMode添加到清单中.
  2. 在那之后不起作用,我在布局中添加了一个EditView字段
  3. 在那之后没有用,我补充道

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) 到onCreate程序.

我用Android2.3.3编译它并尝试在我的Galaxy S2设备和Android4模拟器上运行它仍然 - 没有键盘.

我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

我的main.xml布局:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

我的代码:

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);

    }
}
Run Code Online (Sandbox Code Playgroud)

Muk*_*uky 3

你使用默认的安卓键盘吗?如果您这样做,请在不同的设备上尝试,我知道它有一些问题