问题
I use this:
actionBar.setBackgroundColor(ContextCompat.getColor(this, R.color.action_bar));
To use colors from the color.xml .
It works great, but in some Codes it says:
Wrong 1st argument type. Found: 'org.telegram.ui.ActionBar.BaseFragment', required: 'android.content.Context'
But I import android.content.Context:
import android.content.Context;
I tried to use instead of 'this':
actionBar.setBackgroundColor(ContextCompat.getColor(context, R.color.action_bar));
But than Android Studio say :
Cannot resolve symbol 'context'
回答1:
Use
getActivity().getApplicationContext()
instead of
this
回答2:
Fragment
is not a subtype of Context
.
When inside of a fragment use this:
ContextCompat.getColor(getContext(), R.color.action_bar)
When inside an activity you can use:
ContextCompat.getColor(this, R.color.action_bar)
回答3:
Use :
actionBar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),
R.color.action_bar));
来源:https://stackoverflow.com/questions/35816602/argument-this-doesn%c2%b4t-work-required-android-content-context