我正在使用片段。我在按钮点击时显示了一个弹出窗口。在弹出窗口中,我通过XML添加了编辑文本。在运行时,我无法输入该编辑文本。但是我的光标可见并闪烁。
editText
<EditText android:id="@+id/edtTitle"
android:layout_width="500dp"
android:layout_height="50dp"
android:background="#FFFFFF"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:hint="Event title"
android:paddingLeft="10dp"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="normal"/>
我的活动代码:
public void showPopup() {
LayoutInflater li = LayoutInflater.from(getActivity());
View v = li.inflate(R.layout.popup, null);
PopupWindow window = new PopupWindow(v, width, height);
edtTitle = (EditText) v.findViewById(R.id.edtTitle);
}
任何帮助表示赞赏!!
答案 0 :(得分:0)
更新您的xml代码:
<EditText android:id="@+id/edtTitle"
android:layout_width="500dp"
android:layout_height="50dp"
android:background="#FFFFFF"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:hint="Event title"
android:paddingLeft="10dp"
android:clickable="true"
android:focusable="true"
android:focusableOnTouch="true"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="normal"/>
还要编辑代码并再次检查:
public void showPopup() {
LayoutInflater li = LayoutInflater.from(getActivity());
View v = li.inflate(R.layout.popup, null);
PopupWindow window = new PopupWindow(v, width, height);
Veiw popupView = window.getContentView();
edtTitle = (EditText) popupView.findViewById(R.id.edtTitle);
}
答案 1 :(得分:0)
检查弹出窗口中是否有setOnKeyListener,并确保在不需要该事件时返回false,例如:
OnKeyListener listener = new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//Do something
return true;
}
return false;
}
};
答案 2 :(得分:0)
这是因为PopupWindow没有聚焦,请将构造函数更改为focusable = true
PopupWindow pop = new PopupWindow(popupView1,ViewGroup.LayoutParams.MatchParent,ViewGroup.LayoutParams.WrapContent,true);