I have written code to setFocus to ALert Dialog negative button by using requestFocus(). But the button color will not change.I can able to set background image to that button manually.But i need that one directly from native.How to give focus to second button in ALlert Dialog?
Iam sending the code snippet for understanding
alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus();
Even I tried with
alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus(View.FOCUS_FORWARD)
Please any one can responde on this query?
Regards, Android Developer
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
Just setOnShowListener() to AlertDialog, and set focus on the negative button.
alertDialog.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialog) {
Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
negative.setFocusable(true);
negative.setFocusableInTouchMode(true);
negative.requestFocus();
}
});
alertDialog.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With