Android为片段设置透明背景

在我的应用程序中,我有单个活动和所有其他片段

我正在设置style.xml的活动背景,如下所示

<item name="android:windowBackground">@color/very_light_gray</item>

现在只有一个特定的片段我想设置背景透明,我无法做到尝试下面的片段代码片段对我来说不起作用

@Override
 public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {

// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),R.style.yourCustomTheme);

// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

// inflate the layout using the cloned inflater,not default inflater
return localInflater.inflate(R.layout.yourLayout,container,false);
}

知道怎么做吗?

解决方法

create a callback and implement it in Acitvity

interface OnFragmentdisplay{
  onFragmentdisplay();
}

当此片段显示更新活动背景为透明..或在活动中将其设置为主题

this linkthis可能有所帮助

你试过这个吗?

fragment.getView().setBackgroundColor(Color.WHITE);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...