简体   繁体   中英

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. 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

<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.

In case you get a package clash, add the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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