错误很明显,但是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构造函数具有私有访问权限”,但google docs称该构造函数是公共的。
请帮我解决这个问题。
最佳答案
使用目前最新的23.2.1。(2016年3月)
查看this站点了解更多信息。
我已经用这个版本测试过了。它工作得很好,而事实上,这场争论是公开的。
更新:
好的,我找到了ResouresCompat v24
正如我所料,现在getColor
和getColorStateList
是静态的。所以不需要使用构造函数。
将代码更新为:
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());
但请记住,这只是预览。