2

I've got a custom layout I want to use as the titlebar of my android app. The technique found (linked at the bottom) works, but the system titlebar is displayed before onCreate() is called. Obviously that looks pretty jarring, as for a moment the system titlebar is shown, then my custom titlebar is shown:

// styles.xml
<resources>
  <style name="MyTheme">
    <item name="android:windowTitleSize">40dip</item>
  </style>
</resources>

// One of my activities, MyTheme is applied to it in the manifest.
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.my_activity);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
}

I could always hide the system titlebar and display my own in-line perhaps with each and every layout, but, that's not very friendly.

Thanks

http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/

user291701
  • 38,411
  • 72
  • 187
  • 285
  • Are you trying to not have the system (empty) bar be displayed before your custom bar is displayed? – ahodder Feb 09 '11 at 23:15
  • Well, the custom bar is a layout.xml file - and ideally the app would immediately show that custom layout.xml file. Right now it looks awkward that the system bar is displayed for a second, then replaced by my custom layout.xml bar. – user291701 Feb 10 '11 at 00:45

4 Answers4

3

I think it's a framework limitation. I had the same problem in some of my applications and the ultimate solution was for me to tell the framework I didn't want a title bar at all and then create my own in my layouts. The include directive made it bearable for me, e.g.:

<include layout="@layout/title" />

When I used requestWindowFeature(Window.FEATURE_NO_TITLE) in my activities, I would have the same issue, I'd see the system title bar briefly while the activity was being build when it first loaded.

When I switched to using a theme to tell the framework I didn't want a title, the problem went away and I now see my own title directly on first load. The styling is easy for that:

<style name="FliqTheme" parent="@android:Theme.Black">
    <item name="android:windowNoTitle">true</item>
</style>

I know this doesn't apply to your issue with the custom title, but like ptc mentioned, if you move your custom title into style/theme definitions (which you do by overriding the system title styles in your theme), I think you'll be on the right track.

Jerry Brady
  • 3,050
  • 24
  • 30
  • Yeah I found the same exact problem, shame we have to do it ourselves. We lose the drop shadow effect the system toolbar provides. – user291701 Feb 11 '11 at 06:28
1

The same problem happened to me today when I was trying to custom the title. I solved it by set the android:theme to android:style/Theme.NoTitleBar in the AndroidManifest.xml, and call setTheme() to the actual theme I want in my activity's onCreate callback function.

Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
liuyong
  • 987
  • 10
  • 19
0

The method through setting android:theme does not work for me, I have made it by adding the following code in onCreate() of my Activity subclass:

  getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
gm2008
  • 4,245
  • 1
  • 36
  • 38
0

Try creating a custom theme style in XML and then set your activity's theme attribute in the AndroidManifest.xml file.

http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme

ptc
  • 9
  • 1
  • Hi yes I do have a custom theme but all you can define in there is a background for the titlebar. My custom titlebar is a layout with a few controls on it (like twitter's). So we're stuck at startup showing a funky system titlebar until the real one is shown. – user291701 Feb 10 '11 at 00:48