如何使用.setbackgrounddrawable的资源颜色id



我正在尝试用我在colors.xml文件中定义的两种颜色来为我的工具栏和状态栏上色。

((AppCompatActivity) getActivity())
                .getSupportActionBar()
                .setBackgroundDrawable(?);

window.setStatusBarColor(?);

为了引用R.color.aR.color.b,括号内应该放些什么?

Pass RGB值

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.rgb(248, 248, 248)));

传递资源id

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getContext(),R.color.primary)));

应该是setBackgroundResource(),而不是可绘制的。

最新更新