v.setBackground(ContextCompat.getDrawable(VideoAdapter.this, R.drawable.ic_like2));
时间: 2023-06-20 20:04:45 浏览: 51
这段代码是设置一个View的背景为R.drawable.ic_like2,其中R.drawable.ic_like2是一个资源文件的名称,它应该包含在你的项目的res/drawable目录中。ContextCompat.getDrawable()方法是用来获取一个Drawable对象,它需要传入一个Context对象和一个资源文件的ID。在这里,你传入了VideoAdapter.this作为Context参数,因为这段代码出现在VideoAdapter类中。最终,View的背景将会被设置为R.drawable.ic_like2所代表的图像。
相关问题
v.setBackground(ContextCompat.getDrawable(VideoAdapter.this, R.drawable.ic_like2));中VideoAdapter.this报错
这个错误可能是因为您在非 Activity 或 Fragment 的类中尝试使用 Context。您可以尝试将 `VideoAdapter.this` 替换为 `v.getContext()`,这将返回适当的 Context 对象。例如:
```
v.setBackground(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_like2));
```
这应该可以解决您的问题。
rbText.setBackground(getResources().getDrawable(R.drawable.unselected_background)); rbKeypad.setBackground(getResources().getDrawable(R.drawable.unselected_background)); rbChat.setBackground(getResources().getDrawable(R.drawable.unselected_background));
这段代码的功能是设置三个 RadioButton(rbText、rbKeypad、rbChat)的背景为 unselected_background。其中 R.drawable.unselected_background 是一个 Drawable 资源,可能是一个图片或者是一个 XML 文件。这样设置可以使得这三个 RadioButton 的外观与其他未被选中的 RadioButton 保持一致,从而提高界面的一致性和美观性。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)