2

I did the API check yet its showing deprecation warning while compiling.

private void tab_sel(boolean whi_one){
    View vie1 = findViewById(R.id.tab_sel1);
    View vie2 = findViewById(R.id.tab_sel2);
    int whi, gra, pos, neg;

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        whi = getResources().getColor(R.color.white);
        gra = getResources().getColor(R.color.tabInactive);
    } else {
        whi = getColor(R.color.white);
        gra = getColor(R.color.tabInactive);
    }

    if(whi_one){
        vie1.setVisibility(View.VISIBLE);
        vie2.setVisibility(View.INVISIBLE);
        pos = whi;
        neg = gra;
    } else {
        vie1.setVisibility(View.INVISIBLE);
        vie2.setVisibility(View.VISIBLE);
        pos = gra;
        neg = whi;
    }

    tv_pos_tit.setTextColor(pos);
    tv_pos_bal.setTextColor(pos);
    tv_neg_tit.setTextColor(neg);
    tv_neg_bal.setTextColor(neg);
}

Can anybody tell me while it shows deprecation warning? it shows

whi = getResources().getColor(R.color.white) and 
gra = getResources().getColor(R.color.tabInactive)

as deprecated lines

Kaushik Burkule
  • 816
  • 1
  • 12
  • 27
ItsRedwan
  • 173
  • 1
  • 9
  • 1
    The deprecation warning is a **compiler** warning. You're compiling against a later version where the calls are deprecated. The compiler doesn't know whether the code will be executed at runtime, it simply tells you that the methods you are calling are deprecated in the version you're compiling against. – Andreas Nov 23 '19 at 06:28

1 Answers1

2

Use this ContextCompat.getColor(context,R.color.your_color);

Rujul Gandhi
  • 1,700
  • 13
  • 28