Java Code Examples for androidx.appcompat.app.AlertDialog#setView()

The following examples show how to use androidx.appcompat.app.AlertDialog#setView() . 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: ActivityGlobalAbstract.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void showInfoDialog(String title, String message) {
    if (getActivity() != null) {
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();

        //TITLE
        final View titleView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_title, null);
        ((TextView) titleView.findViewById(R.id.dialogTitle)).setText(title);
        alertDialog.setCustomTitle(titleView);

        //BODY
        final View msgView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_body, null);
        ((TextView) msgView.findViewById(R.id.dialogBody)).setText(message);
        msgView.findViewById(R.id.dialogAccept).setOnClickListener(view -> alertDialog.dismiss());
        msgView.findViewById(R.id.dialogCancel).setOnClickListener(view -> alertDialog.dismiss());
        alertDialog.setView(msgView);


        alertDialog.show();

    }
}
 
Example 2
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
private void createFileName() {
    LayoutInflater inflater = getLayoutInflater();
    Bitmap resizedBitmap = Bitmap.createBitmap(favoriteIcon);
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_shortcut, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.shortcut_name_edittext);
    AlertDialog alertDialog = createExitDialog();
    alertDialog.setTitle(R.string.add_home);
    alertDialog.setView(alertLayout);
    alertDialog.show();
    shortcutNameEditText.setHint(webViewTitle);
    ImageView imageShortcut = alertDialog.findViewById(R.id.fav_imageView);
    if (imageShortcut != null) {
        imageShortcut.setImageBitmap(StaticUtils.getCircleBitmap(resizedBitmap));
    }else{
        Log.d("Null", "");
    }
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 3
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
@SuppressLint("SetTextI18n")
private void createDownload() {
    LayoutInflater inflater = getLayoutInflater();
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_download, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.file_name_edit_text);
    EditText path = alertLayout.findViewById(R.id.file_path_edit_text);
    TextView download_size = alertLayout.findViewById(R.id.down_text);
    TextView download_warn = alertLayout.findViewById(R.id.down_text_warn);
    AlertDialog alertDialog = createDialog();
    alertDialog.setView(alertLayout);
    alertDialog.setCancelable(false);
    alertDialog.show();
    if (UserPreferences.isDangerousFileExtension(filename1)) {
        download_warn.setVisibility(View.VISIBLE);
        download_warn.setText(String.format(getString(R.string.download_warning), filename1));
    }
    shortcutNameEditText.setHint(filename1);
    path.setText(Environment.DIRECTORY_DOWNLOADS);
    download_size.setText(getResources().getString(R.string.download_file) + " " +file_size_main);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 4
Source File: MainActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
private void createFileName() {
    LayoutInflater inflater = getLayoutInflater();
    Bitmap resizedBitmap = Bitmap.createBitmap(favoriteIcon);
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_shortcut, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.shortcut_name_edittext);
    AlertDialog alertDialog = createExitDialog();
    alertDialog.setTitle(R.string.add_home);
    alertDialog.setView(alertLayout);
    alertDialog.show();
    shortcutNameEditText.setHint(webViewTitle);
    ImageView imageShortcut = alertDialog.findViewById(R.id.fav_imageView);
    if (imageShortcut != null) {
        imageShortcut.setImageBitmap(StaticUtils.getCircleBitmap(resizedBitmap));
    }else{
        Log.d("Null", "");
    }
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
}
 
Example 5
Source File: MainActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
@SuppressLint("SetTextI18n")
public void createDownload() {
    LayoutInflater inflater = getLayoutInflater();
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_download, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.file_name_edit_text);
    EditText path = alertLayout.findViewById(R.id.file_path_edit_text);
    TextView download_size = alertLayout.findViewById(R.id.down_text);
    TextView download_warn = alertLayout.findViewById(R.id.down_text_warn);
    checker = alertLayout.findViewById(R.id.check_off);
    AlertDialog alertDialog = createDialog();
    alertDialog.setView(alertLayout);
    alertDialog.setCancelable(false);
    alertDialog.show();
    if (UserPreferences.isDangerousFileExtension(filename1)) {
        download_warn.setVisibility(View.VISIBLE);
        download_warn.setText(String.format(getString(R.string.download_warning), filename1));
    }
    shortcutNameEditText.setHint(filename1);
    path.setText(Environment.getExternalStorageDirectory().getPath() + File.separator +Environment.DIRECTORY_DOWNLOADS + File.separator + getString(R.string.app_name) + File.separator + "Simplicity Downloads");
    download_size.setText(getResources().getString(R.string.download_file) + " " +file_size_main);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 6
Source File: BaseAlertDialogFragment.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    final View view = getView();
    if (view != null) {
        if (view.getParent() != null) {
            throw new IllegalStateException(
                    "DialogFragment can not be attached to a container view");
        }
        final AlertDialog dialog = getDialog();
        if (dialog != null)
            dialog.setView(view);
    }
    // 屏蔽获取View,避免其将View设置为Dialog的ContentView,否则整个AlertDialog布局将失效
    mBlockView = true;
    super.onActivityCreated(savedInstanceState);
    mBlockView = false;
}
 
Example 7
Source File: ActivityGlobalAbstract.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public AlertDialog showInfoDialog(String title, String message, OnDialogClickListener clickListener) {
    if (getActivity() != null) {
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();

        //TITLE
        final View titleView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_title, null);
        ((TextView) titleView.findViewById(R.id.dialogTitle)).setText(title);
        alertDialog.setCustomTitle(titleView);

        //BODY
        final View msgView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_body, null);
        ((TextView) msgView.findViewById(R.id.dialogBody)).setText(message);
        msgView.findViewById(R.id.dialogAccept).setOnClickListener(view -> {
            clickListener.onPossitiveClick(alertDialog);
            alertDialog.dismiss();
        });
        msgView.findViewById(R.id.dialogCancel).setOnClickListener(view -> {
            clickListener.onNegativeClick(alertDialog);
            alertDialog.dismiss();
        });
        alertDialog.setView(msgView);

        return alertDialog;

    } else
        return null;
}
 
Example 8
Source File: ActivityGlobalAbstract.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public AlertDialog showInfoDialog(String title, String message, String positiveButtonText, String negativeButtonText, OnDialogClickListener clickListener) {
    if (getActivity() != null) {
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();

        //TITLE
        final View titleView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_title, null);
        ((TextView) titleView.findViewById(R.id.dialogTitle)).setText(title);
        alertDialog.setCustomTitle(titleView);

        //BODY
        final View msgView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_body, null);
        ((TextView) msgView.findViewById(R.id.dialogBody)).setText(message);
        ((Button) msgView.findViewById(R.id.dialogAccept)).setText(positiveButtonText);
        ((Button) msgView.findViewById(R.id.dialogCancel)).setText(negativeButtonText);
        msgView.findViewById(R.id.dialogAccept).setOnClickListener(view -> {
            clickListener.onPossitiveClick(alertDialog);
            alertDialog.dismiss();
        });
        msgView.findViewById(R.id.dialogCancel).setOnClickListener(view -> {
            clickListener.onNegativeClick(alertDialog);
            alertDialog.dismiss();
        });
        alertDialog.setView(msgView);

        return alertDialog;

    } else
        return null;
}
 
Example 9
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}
 
Example 10
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}