使用编辑文本在自定义警报对话框上复制/粘贴弹出窗口的错误行为

时间:2018-05-23 02:51:34

标签: android android-edittext android-alertdialog

我正在创建一个带有EditText的自定义AlertDialog。这是我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.MyDialog));
builder.setTitle(R.string.something);
final EditText input = new EditText(context);
input.setText("something");
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
input.setSelectAllOnFocus(true);
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
   inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
FrameLayout container = new FrameLayout(Activity.this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.leftMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin);
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin);
input.setLayoutParams(params);
container.addView(input);
builder.setView(container);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        //some business logic
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
    });
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.cancel();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
    });
AlertDialog dialog = builder.create();
dialog.show();

一切都按预期工作。问题是,当我长按EditText中的文本时,它会显示一个白色的布局,如果我触摸它,则操作被执行,但我无法看到任何内容。这里发生了什么?

custom AlertDialog with a EditText inside

white layout over AlertDialog where should be the copy/paste options

式:

<style name="MyDialog" parent="Theme.AppCompat.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@color/white</item>
    <item name="android:textColorPrimary">@color/textColorPrimary</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

0 个答案:

没有答案