下面的代码显示对话,但不捕捉焦点。如果不像猿一样调用输入法管理器,那么如何才能打开软触摸键盘呢?
EditText editText = new EditText(this);
AlertDialog.Builder odomoter_dialog = new AlertDialog.Builder(this);
AlertDialog dialog = odomoter_dialog.Create();
dialog.ShowEvent += (d, arg) =>
{
editText.RequestFocus();
};
dialog.Show();发布于 2017-05-12 02:53:09
由于@Max只为传统的安卓应用程序提供Java代码,所以我在这里编写这个答案,将其转换为C# for Xamarin.Android应用程序。
例如:
var odomoter_dialog = new AlertDialog.Builder(this);
odomoter_dialog.SetView(Resource.Layout.DiaologView);
var dialog = odomoter_dialog.Create();
dialog.Window.SetSoftInputMode(Android.Views.SoftInput.StateAlwaysVisible);
dialog.Show();我身边的DiaologView是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please enter your name:" />\
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>发布于 2017-05-11 19:17:22
要立即显示键盘,请在dialog.show()之后添加这一行;
odomoter_dialog.show()
.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);如果需要设置焦点,还需要在dialog.Show()之后进行;
附注:不要忘记在焦点视图中使用dialog.findviewbyid
https://stackoverflow.com/questions/43923737
复制相似问题