I have an application which consists of a single activity consisting of a content frame for fragments with a navigation drawer which controls which fragment is displayed.
I'm trying to work out if I can make the action bar transparent for some of the fragments but not for others, looking at
http://developer.android.com/training/basics/actionbar/overlaying.html
and other questions on this site they all seem to give examples of creating different styles for the actionbar and setting these styles on a per activity basis in the manifest, is there a way to do this on a per fragment basis?
You can use getActivity()
method in fragment to get activity context and get the actionbar instance. Then you can do whatever you wish to do with it.
ActionBar actionBar = getActivity().getActionBar();
// replace getActivity() with ((ActionBarActivity)getActivity()) if using appcompat
And then you can set transparent background to id:
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#80000000")));
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.