简体   繁体   中英

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.

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

any help or link would be too much helpful :) thank you.

if it is needed, i can provide the style.xml . i have created them from this actionbar style generator tool

oh my god, i have found the answer in 5 min after posting the questions. 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. on that page i have downloaded the zip file which contains the graphics. in the res/drawable there is a xml which is named ab_background_textured_example . and this is the default background of my actionbar. cheer.

if anyone need know more about it, just comment bellow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM