палитра getvibrantcolor (int) не может быть применена к () в androidx - PullRequest
0 голосов
/ 22 апреля 2020

Здравствуйте. Я сталкиваюсь с ошибкой getvibrantcolor(int) palette cannot be applied to () после переноса кода в Androidx перед его переносом. Пожалуйста, помогите мне решить эту проблему.

Ниже приведен мой код, в котором я инициализирую и использую палитру с растровым изображением -

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

следующее приложение app.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 Ответ

0 голосов
/ 22 апреля 2020

Согласно документации :

publi c int getVibrantColor (int defaultColor)

Так что вам нужно передать значение по умолчанию цвет, который должен быть возвращен, если нет яркого цвета:

// Use whatever default color you want
int defaultColor = getResources().getColor(android.R.color.black);
titleView.setTextColor(palette.getVibrantColor(defaultColor));
...