面对getvibrantcolor(int)调色板无法应用于androidx中的()

问题描述 投票:0回答:1

[您好,在将代码迁移到Androidx之前,我遇到getvibrantcolor(int) palette cannot be applied to ()错误,然后再正常运行。请帮助我解决此问题。

以下是我的代码,其中我正在初始化并使用带位图的调色板-

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());
}

以下为错误图片-enter image description here

以下是应用程序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'
} 
android androidx palette
1个回答
0
投票

根据the documentation

public int getVibrantColor(int defaultColor)

因此,您需要传递默认颜色,如果没有鲜艳的颜色可用,则应返回默认颜色。

© www.soinside.com 2019 - 2024. All rights reserved.