簡體   English   中英

為什么會在alertDialog.Builder而不是popupWindow(android)上顯示軟鍵盤?

[英]Why will soft keyboard appear for alertDialog.Builder but not for popupWindow (android)?

我有一個通過LayoutInflater啟動一系列popupWindows的活動。 其中一個包含一堆EditText,由於某種原因,當我聚焦時,我無法啟動軟鍵盤。 但是,如果我將其從popupWindow切換到alertDialogue.Builder,它就可以正常工作。

為什么會這樣,如何將其用作popupWindow?

AlertDialogue代碼:

AlertDialog.Builder pop_up = new AlertDialog.Builder(this);
pop_up.setView(this.getLayoutInflater().inflate(R.layout.signup_layout, null));
pop_up.show();

PopupWindow代碼:

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>

嘗試這樣.....所有的Edittexts。

EditText edt = (EditText) popupView.findviewbyid(R.id.name_textField);

希望它能工作。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM