Я хотел бы открыть программную клавиатуру, когда начинается действие, и обнаружил, что
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);
}
}