如何将焦点设置到Android警告对话框负按钮? [英] How to set focus to android alert dialog negative button?

查看:884
本文介绍了如何将焦点设置到Android警告对话框负按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以书面requestFocus的code到的setFocus以警告对话框负按钮()。但按钮颜色不会change.I可以能够设置背景图片到该按钮manually.But我需要一个直接从native.How以聚焦在第二个按钮
阿勒特对话?

荫发送code段为理解

  alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus();

即使我试图用

  alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus(View.FOCUS_FORWARD)

请任何一个可以在此查询responde?

问候,
Android开发者


解决方案

只是setOnShowListener()来AlertDialog,并将重点放在负面按钮。

  alertDialog.setOnShowListener(新DialogInterface.OnShowListener(){        @覆盖
        公共无效昂秀(DialogInterface对话){            按钮负= alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
            negative.setFocusable(真);
            negative.setFocusableInTouchMode(真);
            negative.requestFocus();
        }
    });
    alertDialog.show();

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

解决方案

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

这篇关于如何将焦点设置到Android警告对话框负按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆