Java Code Examples for androidx.appcompat.widget.AppCompatEditText#setLayoutParams()

The following examples show how to use androidx.appcompat.widget.AppCompatEditText#setLayoutParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtils.java    From SmartFlasher with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(Objects.requireNonNull(editText.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 2
Source File: BaseDialog.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 设置编辑列表VIEW
 *
 * @param names 编辑view 的name
 * @return this
 */
public BaseDialog setEditViewsName(List<String> names) {
    if (middleLayout.getChildCount() > 0) {
        middleLayout.removeAllViews();
    }

    for (String name :
            names) {
        TextView textView = new TextView(getContext());
        textView.setText(name);
        textView.setTextColor(getContext().getResources().getColor(R.color.base_color_text_black));
        AppCompatEditText editText = new AppCompatEditText(getContext(), null, android.R.attr.editTextStyle);
        editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setHint("请输入" + name);
        editText.setPadding(10, 0, 0, 0);
        editText.setHintTextColor(Color.BLUE);
        LinearLayout child = new LinearLayout(getContext());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        child.setOrientation(LinearLayout.HORIZONTAL);
        child.setGravity(Gravity.CENTER_VERTICAL);
        child.setLayoutParams(params);
        child.addView(textView);
        child.addView(editText);
        middleLayout.addView(child);
    }
    return this;
}
 
Example 3
Source File: ViewUtils.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(Objects.requireNonNull(editText.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 4
Source File: ViewUtils.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(editText.getText().toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 5
Source File: ViewUtils.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2,
                                     final DialogInterface.OnClickListener negativeListener,
                                     final onDialogEditTextsListener onDialogEditTextListener,
                                     Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    if (hint != null) {
        editText.setHint(hint);
    }
    editText.setSingleLine(true);

    final AppCompatEditText editText2 = new AppCompatEditText(context);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    if (text2 != null) {
        editText2.setText(text2);
    }
    if (hint2 != null) {
        editText2.setHint(hint2);
    }
    editText2.setSingleLine(true);

    layout.addView(editText);
    layout.addView(editText2);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog
                .setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                        -> onDialogEditTextListener.onClick(
                        Objects.requireNonNull(editText.getText()).toString(), Objects.requireNonNull(editText2.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 6
Source File: ViewUtils.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2,
                                     final DialogInterface.OnClickListener negativeListener,
                                     final onDialogEditTextsListener onDialogEditTextListener,
                                     Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    if (hint != null) {
        editText.setHint(hint);
    }
    editText.setSingleLine(true);

    final AppCompatEditText editText2 = new AppCompatEditText(context);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    if (text2 != null) {
        editText2.setText(text2);
    }
    if (hint2 != null) {
        editText2.setHint(hint2);
    }
    editText2.setSingleLine(true);

    layout.addView(editText);
    layout.addView(editText2);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog
                .setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                        -> onDialogEditTextListener.onClick(
                        editText.getText().toString(), editText2.getText().toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}