How to set focus to android alert dialog negative button?
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.BUTT开发者_如何转开发ON_NEGATIVE).requestFocus(View.FOCUS_FORWARD)
Please any one can responde on this query?
Regards, Android Developer
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();
精彩评论