我在 PopupWindow 中有一个 EditText,当 PopupWindow 出现时,EditText 中的光标可见,但我无法编辑其文本。
我的代码:
popupwindolalayout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wordfragd2">
<EditText
android:id="@+id/noteedit_popup_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:text="my notes"
android:background="@drawable/wordfragd1"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:padding="10dp"
android:editable="true">
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/noteedit_popup_textview"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:weightSum="2"
>
<Button
android:id="@+id/done_popup_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:layout_weight="1"
android:background="@drawable/wordfragd1"
android:layout_marginRight="1dp"
/>
<Button
android:id="@+id/cancel_popup_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_weight="1"
android:background="@drawable/wordfragd1"
android:layout_marginRight="1dp" />
</LinearLayout>
</RelativeLayout>
用于弹出窗口的 Java:
PopupWindow editnote_popup;
LayoutInflater inflater = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.wordnoteedit_popup,
null);
editnote_popup=new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
editnote_popup.setContentView(view);
editnote_popup.showAtLocation(view, Gravity.CENTER, 0, 0);
我正在处理 fragment 。我在单击按钮时显示了一个弹出窗口。在弹出窗口中,我通过 XML 添加了编辑文本。运行时,我无法输入该编辑文本。但我的光标可见并闪烁。
有什么想法吗?
最佳答案
在此行中添加 true editnote_popup=new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
以使其可聚焦。
它将是:
editnote_popup=new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
关于android - 无法在 PopupWindow 中编辑 EditText 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25085610/