简体   繁体   English

片段设置的透明操作栏

[英]Transparent action bar set by fragment

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 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. 您可以在片段中使用getActivity()方法来获取活动上下文并获取actionbar实例。 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: 然后您可以将透明背景设置为id:

actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#80000000")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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