As @CommonsWare points out, it's impossible that I wanted without rewriting PreferenceActivity, and that seems like a load.
The not-so-elegant solution I settled on was to create two PreferenceActivities ( as shown here ), as well as create two subclasses of Fragment, one for each fragrance of the Fragment.
So, PrefsActivityHC adds this header:
<header <!-- An android.app.Fragment subclass --> android:fragment="com.example.project.MyFragmentHC" </header>
... while PrefsActivity adds this preference:
<Preference> <intent <!-- A v4.support.app.Fragment subclass, wrapped in an ActivityFragment --> android:targetClass="com.example.project.MyFragmentActivity" android:targetPackage="com.example.project" > </intent> </Preference>
To minimize the duplication of code required for two fragments close to it, I created the MyFragmentDelegate class, which supports common fragment methods, and checked an instance of this in MyFragment and MyFragmentHC . Then the method calls in these fragments are simply passed to the delegate:
class MyFragment { MyFragmentDelegate mDelegate; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return mDelegate.onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) } } class MyFragmentHC { MyFragmentDelegate mDelegate; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return mDelegate.onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) } }
source share