Prompt on android Lollipop with misaligned button

Asked

Viewed 32 times

1

I have a problem in a prompt, on Android Kitkat (19) or previous version looks like this:

inserir a descrição da imagem aqui

But in Lollipop or newer versions it is misaligned:

inserir a descrição da imagem aqui

Follow the code of the Lieutenant who makes this code:

final AlertDialog dialog = builder.create();

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            public void onShow(final DialogInterface dialogInterface) {
                Button noButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
                Button yesButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);

                noButton.setTextColor(Color.parseColor("#333333"));
                yesButton.setTextColor(Color.parseColor("#333333"));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Drawable buttonDrawableNo = getResources().getDrawable(R.drawable.button_prompt, context.getTheme());
                    Drawable buttonDrawableYes = getResources().getDrawable(R.drawable.button_prompt, context.getTheme());

                    noButton.setBackground(buttonDrawableNo);
                    yesButton.setBackground(buttonDrawableYes);
                }
                else
                {
                    Drawable buttonDrawableNo = getResources().getDrawable(R.drawable.button_prompt);
                    Drawable buttonDrawableYes = getResources().getDrawable(R.drawable.button_prompt);

                    if (Build.VERSION.SDK_INT > 15) {
                        noButton.setBackground(buttonDrawableNo);
                        yesButton.setBackground(buttonDrawableYes);
                    } else {
                        noButton.setBackgroundDrawable(buttonDrawableNo);
                        yesButton.setBackgroundDrawable(buttonDrawableYes);
                    }
                }
                noButton.invalidate();
                yesButton.invalidate();
            }
        });
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.