I am trying to apply custom theme to ActionBar
in PreferenceFragment
. Following is the scenerio:
My class extends PreferenceFragment
in which I am adding preferences from resouces as:
addPreferenceFromResource (R.xml.myPrefs);
Also, I have written:
ActionBar a = getActivity ().getActionBar ();
bar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS);
Now I want to apply my own theme that I defined in styles.xml
to this action bar. Currently, the height of action bar is smaller that the tab view due to which the view is getting cropped.
I tried searching but couldn't find a solution to my problem.
From 1. and 2. links above, I learnt that:
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);
But this also didn't work.
Any help is highly appreciated.
Finally found solutions to my problem. Seems like there was a simple solution while I tangled myself into complex things.
I just added the following line to the
onCreate ()
of myPreferenceFragment
class... and everything became perfect!Hope it helps someone who might face the same problem! :)