Android 工具栏颜色赢了';t空气污染指数的变化<;23
我用这段代码更改了棒棒糖设备中的工具栏Android 工具栏颜色赢了';t空气污染指数的变化<;23,android,android-studio,android-toolbar,Android,Android Studio,Android Toolbar,我用这段代码更改了棒棒糖设备中的工具栏 toolbar.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.colorWhite)); 但是当我尝试在API19中使用我的应用程序时。 工具栏颜色不会改变 试试看 int color = getApplicationContext().getResources().getColor(R.color.colorWhite); toolba
toolbar.setBackgroundColor(
ContextCompat.getColor(getApplicationContext(), R.color.colorWhite));
但是当我尝试在API19中使用我的应用程序时。工具栏颜色不会改变 试试看
int color = getApplicationContext().getResources().getColor(R.color.colorWhite);
toolbar.setBackgroundColor(color);
setSupportActionBar(toolbar)
编辑:正确的,因为API已经改变,并且现在已经发生了一次去润滑,我建议这样做
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.MARSHMALLOW){
//set using depricated code [one i put earlier]
}else{
//set using latest api;s [ones which youre currently using]
}
if(android.os.Build.VERSION.SDK\u INT
试试这个工具栏。setBackgroundDrawable(新的可着色(“颜色”))代码>“颜色”?我应该在那里放什么。例如:toolbar.setBackgroundDrawable(新的ColorDrawable(ContextCompat.getColor(context,R.color.red))代码>拼写和格式改进。使用AppCompat
并在style.xml
中使用colorPrimary
。我就是这么做的。getResources.getColor是不推荐的ContextCompat.getColor()是类似的。是的,很抱歉忘记了api23,请尝试编辑…我使用了类似这样的东西来处理棒棒糖中的通知,直到appcompat利用新的功能。