Android为片段设置透明背景

前端之家收集整理的这篇文章主要介绍了Android为片段设置透明背景前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我有单个活动和所有其他片段

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

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

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

  1. @Override
  2. public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
  3.  
  4. // create ContextThemeWrapper from the original Activity Context with the custom theme
  5. final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),R.style.yourCustomTheme);
  6.  
  7. // clone the inflater using the ContextThemeWrapper
  8. LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
  9.  
  10. // inflate the layout using the cloned inflater,not default inflater
  11. return localInflater.inflate(R.layout.yourLayout,container,false);
  12. }

知道怎么做吗?

解决方法

create a callback and implement it in Acitvity

  1. interface OnFragmentDisplay{
  2. onFragmentDisplay();
  3. }

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

this linkthis可能有所帮助

你试过这个吗?

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

猜你在找的Android相关文章