【发布时间】:2018-02-25 13:43:02
【问题描述】:
在我的应用中,我有单个活动和所有其他片段
我正在为 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);
}
知道怎么做吗?
【问题讨论】:
-
想给一个背景设置透明背景
-
- @color/very_light_gray
设置了样式,并且该主题应用于活动,因此所有片段都有背景very_light_gray,现在用于特定片段我想要设置背景透明无法做到这一点 -
xml 的背景属性应该可以工作...请向我们展示您的片段和活动布局
-
什么意思?片段是透明的,除非你用可见的背景膨胀布局。那么,您到底想达到什么目的?您拥有什么和想要什么的屏幕截图可能会有所帮助。
-
已有透明背景的充气片段
标签: android android-fragments android-activity android-support-library android-theme