【发布时间】:2014-11-22 02:54:31
【问题描述】:
我在一个片段中,我想在用户单击按钮时更改操作栏颜色并查看背景颜色。无论用户选择什么颜色,我目前在下面的代码都会导致操作栏变灰。
private void changeColor( int colorId ) {
ActionBar actionBar = ((ActionBarActivity )getActivity()).getSupportActionBar();
actionBar.setBackgroundDrawable( new ColorDrawable( colorId ) );
this.getView().setBackgroundColor( getResources().getColor( colorId ) );
}
我的styles.xml 中的动作栏主题为蓝色,不确定这是否有任何效果。如果您有任何建议,请告诉我。
谢谢, 内森
解决方案: 不得不改变:
actionBar.setBackgroundDrawable( new ColorDrawable( colorId ) );
收件人:
actionBar.setBackgroundDrawable( new ColorDrawable( getResources().getColor( colorId ) ) );
【问题讨论】:
-
如果从 styles.xml 中删除蓝色会怎样?
-
同样的问题,我还注意到,当我尝试在我的列表视图行之一上设置线性布局的背景颜色时,我得到相同的灰色。 holder.titleLayout.setBackgroundColor(item.getColorCode());
-
@Nath5,请不要在 cmets 中回答问题。
标签: android colors android-actionbar android-appcompat