suren paleru
suren paleru

Reputation: 75

ResourcesCompat constructor has private acess

error is very clear but the google android docs says the constructor is public.

I've used below code in my app

import android.support.v4.content.res.ResourcesCompat;

final ResourcesCompat resourcesCompat = new ResourcesCompat();
    final int foreground = resourcesCompat.getColor(getResources(), night ? R.color.night_status_bar_text : R.color.status_bar_text, getTheme());
    final int background = resourcesCompat.getColor(getResources(), night ? R.color.night_game_background : R.color.game_background, getTheme());
    statusBar.setTextColor(foreground);

I've added android-v4 support library latest one (support-v4 24.0.0). Android studio is giving 'ResourcesCompat constructor has private access' but google docs says that constructor is public.

Please help me to get solve this.

Upvotes: 3

Views: 423

Answers (1)

daemmie
daemmie

Reputation: 6460

Use 23.2.1 which is the latest at the moment. (March 2016)

Check out this site for more informations.

I've tested it with this version. It works fine and the contructor is in fact public.

Update:

OK I found it ResouresCompat v24

As I expected getColor and getColorStateList are static now. So there is no need to use a constructor.

Update your code to:

final int foreground = ResouresCompat.getColor(getResources(), night ? R.color.night_status_bar_text : R.color.status_bar_text, getTheme());
final int background = ResouresCompat.getColor(getResources(), night ? R.color.night_game_background : R.color.game_background, getTheme());

But keep in mind that this is just the preview.

Upvotes: 1

Related Questions