C# 如何使用AlertDialog ShowEvent获取对话框中编辑文本的焦点?

C# 如何使用AlertDialog ShowEvent获取对话框中编辑文本的焦点?,c#,android,xamarin.android,C#,Android,Xamarin.android,以下代码显示对话,但不获取焦点。如何在不像猿一样调用输入法管理器的情况下打开软触摸键盘 EditText editText = new EditText(this); AlertDialog.Builder odomoter_dialog = new AlertDialog.Builder(this); AlertDialog dialog = odomoter_dialog.Create(); dialog.ShowEvent += (d, arg) =&g

以下代码显示对话,但不获取焦点。如何在不像猿一样调用输入法管理器的情况下打开软触摸键盘

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

要立即显示键盘,请在dialog.show()之后添加此行

如果需要设置焦点,还需要在dialog.Show()之后设置


p、 s.别忘了为焦点视图使用用户dialog.findviewbyid

要立即显示键盘,请在dialog.show()之后添加此行

如果需要设置焦点,还需要在dialog.Show()之后设置


p、 别忘了在焦点视图中使用user dialog.findviewbyd

,因为@Max只为传统的Android应用程序提供Java代码,所以我在这里写下这个答案,将其转换为Xamarin.Android应用程序的C

例如:

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();
dialogview
在我身边是这样的:

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

\

因为@Max只为传统的Android应用程序提供Java代码,所以我在这里写这个答案是为了将Xamarin.Android应用程序的Java代码转换为C

例如:

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();
dialogview
在我身边是这样的:

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

\

AlertDialog.Builder=新建AlertDialog.Builder(上下文);View ViewInfluded=LayoutFlater.from(上下文)。充气(R*,null,false);builder.setView(viewView);setPositiveButton();builder.show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u输入状态始终可见);AlertDialog.Builder=新建AlertDialog.Builder(上下文);View ViewInfluded=LayoutFlater.from(上下文)。充气(R*,null,false);builder.setView(viewView);setPositiveButton();builder.show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u输入状态始终可见);因此,似乎您必须创建自定义布局以避免使用
InputMethodManager
。@Michael Gabay,是的,我为对话框设置了布局,因为我以为您希望在代码中向对话框添加edittext。这只在有edittext的情况下有效,否则我们需要使用您所说的“InputMethodManager”。因此,似乎您必须创建自定义布局以避免使用
InputMethodManager
。@Michael Gabay,是的,我为dialog设置了布局,因为我以为您想在代码中向对话框添加edittext。这仅在有EditText时有效,否则我们需要使用您所说的“InputMethodManager”。