[英]change the background of actionbar from java code as defined in the style.xml
i have set the theme as: 我将主题设置为:
<application
........
android:theme="@style/Theme.Example" >
.......
.......
</application>
i have several fragment in one activity. 我在一项活动中有几个片段。 in one of my fragment i have change the color of actionbar as:
在我的片段之一中,我将操作栏的颜色更改为:
((MainActivity)getActivity()).getSupportActionBar()
.setBackgroundDrawable(new ColorDrawable(bitmap1.getPixel(0, 0)));
this works fine. 这很好。 now, i want to change the actionbar as it defined in
@style/Theme.Example
while i am traveling to another fragment. 现在,我要更改在
@style/Theme.Example
定义的操作@style/Theme.Example
而我要移动到另一个片段。
after googling for several times, i find out only how to change the color or backround drawable of actionbar. 谷歌搜索几次后,我只找到如何更改颜色或操作栏的背景可绘制。 not how to get back to the default actionbar style as it is defined in the style.xml
而不是如何恢复在style.xml中定义的默认操作栏样式
any help or link would be too much helpful :) thank you. 任何帮助或链接都将非常有帮助:)谢谢。
if it is needed, i can provide the style.xml
. 如果需要,我可以提供
style.xml
。 i have created them from this actionbar style generator tool 我已经从这个actionbar样式生成器工具创建了它们
oh my god, i have found the answer in 5 min after posting the questions. 哦,天哪,我在发布问题后的5分钟内找到了答案。 i have used this:
我用了这个:
Drawable d = getResources().getDrawable(R.drawable.ab_background_textured_example);
((MainActivity)getActivity()).getSupportActionBar().setBackgroundDrawable(d);
if you are asking that what the hell is R.drawable.ab_background_textured_example
is, then you need to read my question properly and check out the link. 如果您询问
R.drawable.ab_background_textured_example
是什么,那么您需要正确阅读我的问题并查看链接。 on that page i have downloaded the zip file which contains the graphics. 在该页面上,我下载了包含图形的zip文件。 in the
res/drawable
there is a xml
which is named ab_background_textured_example
. 在
res/drawable
有一个名为ab_background_textured_example
的xml
。 and this is the default background of my actionbar. 这是我的操作栏的默认背景。 cheer.
欢呼。
if anyone need know more about it, just comment bellow. 如果有人需要了解更多信息,请在下面发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.