0

Hello I am facing getvibrantcolor(int) palette cannot be applied to () error after migrating code to Androidx before migrating it was working good. please help me to resolve this issue.

following is my code where i am initializing and using Palette with Bitmap -

Bitmap photo = setupPhoto(getIntent().getIntExtra("photo", R.drawable.xyz));
colorize(photo);

private void colorize(Bitmap photo) {
    Palette palette = Palette.generate(photo);
    applyPalette(palette);
}

private void applyPalette(Palette palette) {
    getWindow().setBackgroundDrawable(new ColorDrawable(palette.getDarkMutedColor().getRgb()));

    TextView titleView = findViewById(R.id.title);
    titleView.setTextColor(palette.getVibrantColor().getRgb());

    TextView descriptionView = findViewById(R.id.description);
    descriptionView.setTextColor(palette.getLightVibrantColor().getRgb());

    colorRipple(R.id.info, palette.getDarkMutedColor().getRgb(),
            palette.getDarkVibrantColor().getRgb());
    colorRipple(R.id.star, palette.getMutedColor().getRgb(),
            palette.getVibrantColor().getRgb());

    View infoView = findViewById(R.id.information_container);
    infoView.setBackgroundColor(palette.getLightMutedColor().getRgb());

    AnimatedPathView star = findViewById(R.id.star_container);
    star.setFillColor(palette.getVibrantColor().getRgb());
    star.setStrokeColor(palette.getLightVibrantColor().getRgb());
}

Following is error image - enter image description here

following is app build.gridle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.xxx.xxx.info"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-identity:17.0.0'
    implementation 'androidx.palette:palette:1.0.0'
} 

1 Answers1

0

As per the documentation:

public int getVibrantColor (int defaultColor)

So you need to pass in a default color that should be returned if no vibrant color is available:

// Use whatever default color you want
int defaultColor = getResources().getColor(android.R.color.black);
titleView.setTextColor(palette.getVibrantColor(defaultColor));
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443