android - ResourcesCompat 构造函数具有私有(private)访问权限

标签 android constructor android-support-library

错误很明显,但 google android 文档说构造函数是公开的。

我在我的应用中使用了以下代码

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);

我添加了最新的 android-v4 支持库 (support-v4 24.0.0)。 Android Studio 提供“ResourcesCompat 构造函数具有私有(private)访问权限”,但谷歌文档表示该构造函数是公开的。

请帮我解决这个问题。

最佳答案

使用目前最新的23.2.1。 (2016 年 3 月)

查看 this网站了解更多信息。

我已经用这个版本测试过了。它工作正常,构造函数实际上是公开的。

更新:

好的,我找到了 ResouresCompat v24

如我所料,getColorgetColorStateList 现在是静态的。因此无需使用构造函数。

将您的代码更新为:

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());

但请记住,这只是预览。

关于android - ResourcesCompat 构造函数具有私有(private)访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36028175/

相关文章:

android - Jetpack 导航组件上具有不同行为的后退和向上按钮

使用 GCM 的 Android 聊天应用

c++ - 如何在C++中创建指针数组

C++ 构造函数初始化

android - 在 AppBarLayout 折叠之前防止 RecyclerView 在 AppBarLayout 下滚动

Android 支持库抛出 Resources Not Found 异常

Android getIntent() 每次都在 onResume() 中返回相同的 Intent 。如何清除 bundle 中的 int 字段?

java - 如何运行位于 android 模块内的单元测试?

c++ - 使用枚举作为模板参数 C++

android - Android中没有静态方法setOnApplyWindowInsetsListener异常