争论这是行不通的.[必填:"android.content.context" [英] Argument this doesn´t work. [required: 'android.content.context'
本文介绍了争论这是行不通的.[必填:"android.content.context"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这个:
actionBar.setBackgroundColor(ContextCompat.getColor(this, R.color.action_bar));
要使用color.xml中的颜色.
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'
但是我导入了android.content.Context:
But I import android.content.Context:
import android.content.Context;
我试图用它代替'this':
I tried to use instead of 'this':
actionBar.setBackgroundColor(ContextCompat.getColor(context, R.color.action_bar));
但不是Android Studio说:
But than Android Studio say :
Cannot resolve symbol 'context'
推荐答案
使用
getActivity().getApplicationContext()
代替
this
这篇关于争论这是行不通的.[必填:"android.content.context"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文