How to set focus to android alert dialog negative button?

前端 未结 1 1320
一向
一向 2021-01-17 18:37

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 butt

1条回答
  •  礼貌的吻别
    2021-01-17 19:19

    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();
    

    0 讨论(0)
提交回复
热议问题