19

Basically I want to set my activity's theme in the manifest as follows:

android:theme="@android:style/Theme.Translucent.NoTitleBar"

And I want my activity to load up a ListFragment with the theme, Theme.Holo.Dialog (defined in my own style), however I can't just call setStyle(....) in my fragment as I could if it were a DialogFragment.

I believe that I should be able to use a ContextThemeWrapper but I'm having trouble understanding the calls I need to make. So far in my onCreateView I have:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LayoutInflater newInflater = inflater.cloneInContext(new ContextThemeWrapper(getActivity(), R.style.DialogThemeSelector));
    View inflatedView = newInflater.inflate(R.layout.favourites_print, container, false);
    .....

But this is not working. Thanks in advance. Peter.

*Edit * Posting style:

<style name="DialogThemeSelector" parent="@android:style/Theme.Holo.Dialog"/>
4

4 回答 4

2

尝试获取新的LayoutInflater而不是转换提供的,如下所示:

Context newContext = new ContextThemeWrapper(getActivity(), R.style.DialogThemeSelector);
LayoutInflater newInflater = (LayoutInflater) newContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View inflatedView = newInflater.inflate(R.layout.favourites_print, container, false);

如果这不起作用,我怀疑您的style.

于 2012-04-15T07:49:07.627 回答
1

我只是以天真的方式来做:我使用style属性在 XML 中定义我的列表项布局,它似乎工作。我的列表项不太关心它们是否在片段中。我没有尝试对片段本身进行样式设置,但由于列表项是其中唯一的内容,因此对它们进行样式设置似乎就足够了。

于 2012-03-21T09:43:38.560 回答
1

尝试使用 requestWindowFeature(Window.FEATURE_NO_TITLE); 而不是 android: theme="@android:style/Theme.Translucent.NoTitleBar"

并放入清单 targetSdkVersion="14" 以供使用 Theme.Holo。

于 2012-04-17T02:55:41.367 回答
1

也许我误解了,但你不能只在清单中为包含列表片段的活动设置主题吗?

编辑:在调查之后,我最好的建议是查看 dialogfragment 的来源并尝试在您自己的 customfragment 中复制行为。

或者

在新的 FragmentActivity 中启动您的 Fragment =/

于 2012-04-10T15:51:05.877 回答