Android如何实现对系统自带对话框标题栏进行修改

先上一张图可以看到,对话框的标题颜色是蓝色的,下面还有一根线也是蓝色的,在某些情况下,我们想改变程序的主题风格,颜色必须做修改,但又懒得去定制Dialog,下面的方法就诞生了:

 public static final void dialogTitleLineColor(Dialog dialog, int color) {
        Context context = dialog.getContext();
        /*int divierId = context.getResources().getIdentifier("android:id/titleDivider", null, null);
        View divider = dialog.findViewById(divierId);
        divider.setBackgroundColor(color);*/
        int divierId = context.getResources().getIdentifier("android:id/alertTitle", null, null);
        TextView divider = (TextView)dialog.findViewById(divierId);
        divider.setTextColor(backgroundColor);
    }

此方法可以改变 对话框的标题颜色和标题下面的横线颜色,其中改变横线颜色已经被我注释掉。


举一反三,大家想改变系统控件的什么属性均可以通过,context获得资源id,然后得到该资源的实例,最后修改该实例的属性。修改后的效果如下


android在5.0后出来了material design,俺也把很久前做的APP采用material design翻新了一下!欢迎下载使用!

http://shouji.baidu.com/soft/item?docid=6936655

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章