Android系统应用开发(八)ANR应用程序与无响应对话框自定义


1, 在源码下搜,grep "已停止运行" -r ,找到他的字段名,搜到id为"aerr_application"的字段

2,继续搜 ,grep "aerr_application" -r ,看他在那里用到,搜到 AppErrorDialog的文件,位置:Z:\myandroid\frameworks\base\services\java\com\android\server\am,但是这个文件里面没见用到style,那么看他的基类,AppErrorDialog extends BaseErrorDialog
3,BaseErrorDialog 里面看到 super(context, com.android.internal.R.style.Theme_Dialog_AppError);好了,去找这个style,当然是在frameworks\base\core\res\res\theme里面
class BaseErrorDialog extends AlertDialog {
    public BaseErrorDialog(Context context) {
        super(context, com.android.internal.R.style.Theme_Dialog_AppError);


        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        WindowManager.LayoutParams attrs = getWindow().getAttributes();
        attrs.setTitle("Error Dialog");
        getWindow().setAttributes(attrs);
        setIconAttribute(R.attr.alertDialogIcon);
    }

4,在style里面搜,改变 @android:color/transparent发现并没卵用,这是dialog的整体背景,titlebar和下面的button有自己的背景,那么看他基类Theme.Holo.Dialog
 
    

5,找到Theme.Holo.Dialog,其中的  @android:style/Holo.ButtonBar.AlertDialog就是下面的button的样式,继续找Holo.ButtonBar.AlertDialog,在style里面



6,在Holo.ButtonBar.AlertDialog,其中的@color/white就是下面button的背景色,下面接着找上面titlebar的背景


7,卧槽,花了一下午时间,刚找到,改变他的背景的地方,他应该不是titlebar的背景,这个dialog没有title
返回到低(4)步里面    @null这个就是改变"xx已停止运行"的背景的,我改成@android:color/white
看到效果了;

    


特定应用“xxx”已停止运行对话框做修改,文件位置Z:\myandroid\frameworks\base\services\java\com\android\server\am\AppNotRespondingDialog.java


说明:

1 String processName=name2 != null? res.getString(resid,name1.toString(), name2.toString()): res.getString(resid, name1.toString());自己定义一个字符串,获取停止的英明的名字,这个字符串中包含你的应用的名称,比如你的应用名为“File”,那么他的打印出来就是“File  xxx”xxx是我忘了,打过log,但是processName绝对不止是你的应用名,自己可以打印出来看一下,

2processName.contains("File")用这个方法判断只要包含你的应用的名称,改了dialog的显示内容即可,比如我这里改了dialogmessagesetMessage("waita moment please! ");title的修改

setTitle("Tips.");这都是在源码里面修改,字符串不能直接用中文加引号


你可能感兴趣的:(android系统开发,Android,Framework开发)