我在DialogFragment上遇到这个问题,带有输入编辑文本框,当弹出对话框并触摸文本框输入时,键盘显示并立即隐藏,向上和向下推动弹出对话框。因此,我无法投入任何东西。
这是对话片段代码
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import com.test.abc.testingapppay.R;
public class AlertCaptureItemQuantity extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_quantity_prompt,null);
final EditText quantity = (EditText) view.findViewById(R.id.text_quantity);
quantity.requestFocus();
return new AlertDialog.Builder(getActivity())
.setView(view)
.setTitle("Quantity")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
// val_quantity =Double.parseDouble(quantity.getText().toString());
Intent i = new Intent().putExtra("quantityEntered", quantity.getText().toString());
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
if (quantity.getText().length() > 0) {
dismiss();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
dismiss();
}
}).create();
}
}
和主要活动的主要呼叫
AlertCaptureItemQuantity AlertDialogItems= new AlertCaptureItemQuantity();
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();//getFragmentManager();
AlertDialogItems.show(fragmentManager.beginTransaction(),"items");
对话框的活动xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/text_quantity"
/>
</LinearLayout>