简体   繁体   中英

Change the color of an actionbar on an activity from a package

I have an Android app that uses a third-party library to perform some camera functions. And it works great! The library displays a new activity that allows you to use the camera and access the photo-reel.

However, I would like to see if I can change the color of the ActionBar in the activity. Since the activity is inside the library, the only thing I have access to (object-wise) is the intent that is created using the code:

Intent intent = new Intent(context, GalleryActivity.class);

Is there any way to access the activity from an intent ? And then from the activity, get to the ActionBar to change the color of it? Or would I be required to pull the source directly into my own project and modify it there?

Im not sure what you would accomplish by changing the bar color before you create the activity, but heres how you would do it once it exists.

You would do this programmatically in your onCreate() method.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setBackgroundDrawable(*your color here*);

Should do the trick

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