简体   繁体   English

传递整数而不是资源颜色

[英]Pass integer instead of resource color

I am using a library to show some nice dialogs. 我正在使用一个来显示一些不错的对话框。 I now came to the point where I am getting crashes. 我现在到了崩溃的地步。 If I pass a resource (Eg. R.color.thatRedColor), the dialog will have a red background color. 如果我传递资源(例如R.color.thatRedColor),则对话框将具有红色背景色。 When I am passing an Integer (as it should be used), the app just crashes.. Is there any way that I can pass a valid value using an Integer? 当我传递一个整数(应该使用)时,应用程序崩溃了。是否有任何方法可以使用整数传递有效值?

The used line in my colors.xml 我的colors.xml中使用的行

<color name="indigo">#3f51b5</color>

My code 我的密码

int primaryColor = 11243910;

new MaterialStyledDialog(context)
    .setHeaderColor() //If I pass R.color.indigo, it works. If I pass primaryColor, it crashes..
    .setDescription("Hello")
    .setPositive("Ok", new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            //Do something
        }
    })
    .setNegative("No", new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            //Don't do anything
        }
    })

    .withDivider(false)
    .show();

Based on the source code, use setHeaderColorInt() , not setHeaderColor() , to pass an actual color value instead of a color resource ID. 根据源代码,使用setHeaderColorInt()而不是setHeaderColor()传递实际颜色值而不是颜色资源ID。

In case you get a package clash, add the following: 如果遇到软件包冲突,请添加以下内容:

compile ('com.github.javiersantos:MaterialStyledDialogs:1.5.5') {
    exclude group: 'com.afollestad.material-dialogs';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM