我的应用程序只有一个活动和其他所有片段。
我通过以下方式从style.xml中设置活动的背景:
<item name="android:windowBackground">@color/very_light_gray</item>
现在我只想将特定的Fragment设置为透明背景,但我无法做到。在Fragment中尝试了下面的代码,但对我没有用。
@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);
}
你有任何想法如何做到这一点吗?