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 开发者_StackOverflow中文版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"/>
Try getting a new LayoutInflater
instead of converting the provided one, like so:
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);
If that doesn't work, I would suspect that there may be something missing in your style
.
I just do it the naive way: I define my list item layouts in XML, using the style
attribute, and it seems to work. My list items are not so much concerned with whether they are in a fragment or not. I have not tried styling the fragment itself, but since the list items are the only thing in it, styling them seems sufficient.
Try to use requestWindowFeature(Window.FEATURE_NO_TITLE); instead of android: theme="@android:style/Theme.Translucent.NoTitleBar"
And put in the manifest targetSdkVersion="14" for use Theme.Holo.
Maybe I'm misunderstanding but can't you just set the theme in the manifest for the activity that holds the listfragment?
Edit: After looking into it my best advice is to look at the source of dialogfragment and try to replicate the behavior in your own customfragment.
OR
Start your fragment up in a new fragmentactivity =/
精彩评论