我有一个通过 LayoutInflater 启动一系列 popupWindows 的活动。其中一个有一堆 EditText,由于某种原因,当它们聚焦时,我无法启动软键盘。但是,如果我将它从 popupWindow 切换到 alertDialogue.Builder,它就可以正常工作。
为什么会这样,我怎样才能让它作为弹出窗口工作?
警报对话代码:
AlertDialog.Builder pop_up = new AlertDialog.Builder(this);
pop_up.setView(this.getLayoutInflater().inflate(R.layout.signup_layout, null));
pop_up.show();
弹出窗口代码:
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.signup_layout, null);
PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
popupWindow.showAtLocation(view, 1, 0, 0);
和xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#C417375E"
android:gravity="center"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/popup_background"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="15dp" >
<Button
android:id="@+id/back_button"
android:layout_width="150dp"
android:layout_height="40dp"
android:background="@drawable/popup_background"
android:text="Back"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Email or Phone Number"
android:textColor="#ffffff"
android:textSize="30sp" />
<EditText
android:id="@+id/email_textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Choose a Password"
android:textColor="#ffffff"
android:textSize="30sp" />
<EditText
android:id="@+id/password_textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Confirm Password"
android:textColor="#ffffff"
android:textSize="30sp" />
<EditText
android:id="@+id/confirm_password_textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Zip Code(optional)"
android:textColor="#ffffff"
android:textSize="30sp" />
<EditText
android:id="@+id/zipcode_textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Your First Name (optional)"
android:textColor="#ffffff"
android:textSize="30sp" />
<EditText
android:id="@+id/name_textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/done_button"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/popup_background"
android:onClick="onClick_thanksForSigningUp"
android:text="Done"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>