PreferenceActivity with custom title

Once I faced a problem. I couldn’t implement custom title bar for PreferenceActivity. All the time I was getting exception like:

02-13 16:49:52.532: E/AndroidRuntime(623): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.coffeedriven.fuel/org.coffeedriven.fuel.SettingsActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

I finally managed to find solution for this problem. Look at this code example:

public class SettingsActivity extends PreferenceActivity {

	private ResultsDbAdapter resultsAdapter = ResultsDbAdapter.getInstance(this);

	protected void onCreate(Bundle savedInstanceState) {
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
		TextView customTitleText = (TextView) findViewById(;

And of course my title template is simple LinearLayout with ImageView and TextView inside. Nothing special.

If you find better way to implement custom title with PreferenceActivity please share :) I will be more than happy, because this code looks ugly.