我建议使用Handler
与postDelayed(...)
方法及您指定的延迟时间后,打开键盘:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et= (EditText) findViewById(R.id.editText1);
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
}
}, 5000); // delay in milliseconds
}
您所需的延迟时间后,这将打开键盘。
这里我.xml文件:(请注意<requestFocos />
标签)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
让我错了,如果我错了,你想,当活动开始,你不想要专注编辑文本和你的后计时器下降,然后你想显示键盘。所以你可以做的是,当活动负载使你编辑文本可聚焦的假,并在计时器任务后使其可聚焦真正和请求焦点到你的编辑文本。 –