我有一个在线性布局中的编辑文本。线性布局位于弹出窗口内。
当我运行应用程序时,我无法单击并输入编辑文本的输入。
弹出窗口的代码,它位于我片段的onCreateView中:
final Button makeoffer = (Button) view.findViewById(R.id.make_offer);
makeoffer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.offer_popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
EditText mEditText = (EditText) popupView.findViewById(R.id.payment_field);
popupView.clearFocus();
mEditText.requestFocus();
popupWindow.setFocusable(true);
popupWindow.update();
final Spinner spinner1 = (Spinner) popupView.findViewById(R.id.transaction_spinner);
spinner1.setAdapter(new ArrayAdapter<CharSequence>(getActivity(), R.layout.support_simple_spinner_dropdown_item,getActivity().getResources().getTextArray(R.array.payment_list)));
Button btnDismiss = (Button)popupView.findViewById(R.id.cancel2);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, 0, 0);
}
});
弹出窗口布局的XML代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent"
android:background="#BF000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:layout_marginTop="120dp"
android:text="Make an Offer"/>
<LinearLayout
android:layout_width="300dp"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_gravity="top|left"
android:background="#FFFFFF"
android:layout_marginBottom="20dp"
android:descendantFocusability="blocksDescendants">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:textColor="#00ff00"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:text="Your Offer: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#000000"
android:textSize="18sp"
android:paddingLeft="10dp"
android:text="$"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="38sp"
android:hint="Amount"
android:id="@+id/payment_field"
android:textColor="#000000"
android:paddingLeft="5dp"
android:background="#FFFFFF"
android:layout_gravity="center_vertical"
android:textColorHint="#000000"/>
</LinearLayout>
<Spinner
android:id="@+id/transaction_spinner"
android:spinnerMode="dialog"
android:layout_width="300dp"
android:layout_height="50dp"
android:popupBackground="#00688B"
android:layout_marginBottom="15dp"
android:layout_marginLeft="40dp"
android:background="#FFFFFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#00ff00"
android:layout_marginLeft="100dp"
android:textSize="15sp"
android:paddingLeft="10dp"
android:layout_marginBottom="15dp"
android:text="How does this work?"/>
<Button
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="10dp"
android:background="#228b22"
android:text="Review Offer"
android:inputType="textFilter"
android:id="@+id/review_offer"
android:textColor="#FFFFFF"
android:layout_marginBottom="10dp"
/>
<Button
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="10dp"
android:background="#FFFFFF"
android:text="Cancel"
android:inputType="textFilter"
android:id="@+id/cancel2"
android:textColor="#000000"
android:layout_marginBottom="10dp"
/>
答案 0 :(得分:1)
对于其他读这篇文章的人:
非常感谢@AnkiiRawat。 我做的是我摆脱了android:descendantFocusability =&#34; blocksDescendants&#34;在xml文件中。在包含EditText的LinearLayout中我添加了 机器人:descendantFocusability =&#34; afterDescendants&#34;属性。