I have a problem with a prompt, in Android Kitkat (19) or previous version looks like this:
Butinlollipopornewerversionsitismisaligned:
Hereisthelistenercodethatmakesthiscode:
finalAlertDialogdialog=builder.create();dialog.setOnShowListener(newDialogInterface.OnShowListener(){publicvoidonShow(finalDialogInterfacedialogInterface){ButtonnoButton=((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);ButtonyesButton=((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();
}
});