material-dialogs ,MaterialDialog 修改字体大小

多个项目中都用到了material-dialogs,通常默认字体大小已经可以了,但总会遇到特殊的需求,找了各种修改方法都无法很好地满足需求,例如:明明可以很简单的修改,还要去重写进行自定义

  • 使用方法
implementation 'com.afollestad.material-dialogs:commons:0.9.4.2' 
  • 修改前
MaterialDialog dialog = new MaterialDialog.Builder(this)
                .title("提示")
                .content(getString(R.string.warn_not_same_network))
                .positiveText("确定")
                .show();
修改前的效果
  • 修改后
MaterialDialog dialog = new MaterialDialog.Builder(this)
                .title("提示")
                .content(getString(R.string.warn_not_same_network))
                .positiveText("确定")
                .build();

        if (dialog.getWindow() != null){
            dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        }
        if (dialog.getTitleView() != null){
            dialog.getTitleView().setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.dialogTitleTextSize));
        }
        if (dialog.getContentView() != null){
            dialog.getContentView().setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.dialogContentTextSize));
        }
        if (dialog.getActionButton(DialogAction.NEGATIVE) != null){
            dialog.getActionButton(DialogAction.NEGATIVE).setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.dialogBtnTextSize));
        }
        if (dialog.getActionButton(DialogAction.POSITIVE) != null){
            dialog.getActionButton(DialogAction.POSITIVE).setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.dialogBtnTextSize));
        }

        dialog.show();
修改后的效果
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容