3

I have an application which uses a custom title bar. However, when my application launches, I noticed that the default title bar is shown for a brief period of time. My problem is I don't want to show the default title bar while my application is loading. How do I hide the title bar while my application is loading so that there will be no hint of it and then show it afterwards?

So far, I tried the following solutions but none have worked:

  • Hide the title bar in XML and then set the custom title bar in code. (Problem encountered: I received an error message saying: "You cannot combine custom titles with other title features".)

In XML:

<item name="android:windowNoTitle">true</item>

In onCreate method:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//... some code goes here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_header);
  • Set the size of the title bar in XML to 0. Then change it's size via code later. (Problem encountered: I don't know how to set the size of title bar in code. Is it possible? I tried getWindow().setAttributes() and getWindow().setLayout() but both of them didn't worked.)"

In XML:

<item name="android:windowTitleSize">30dp</item>
  • Modify windowTitleBackgroundStyle and set a transparent drawable as background. (Problem encountered: The content of the title bar became invisible but a line below the title bar is still visible.)

In XML:

<!-- style used by windowTitleBackgroundStyle -->
<item name="android:background">@drawable/transparent</item>
Arci
  • 6,647
  • 20
  • 70
  • 98

3 Answers3

4

Some explanations for what you've encountered, hopefully they help lead you in a direction you're happy with.

You've already seen that your theme is used to generate what you see during activity loading. What's happening is the system is generating a temporary/loading window based on your activity's theme as specified in your manifest while your process is still starting up. Your code may not even be running yet, and your own activity will have a different window. This is significant because a number of settings become locked in once the window's decor has been created, but you actually have two chances here. The window your activity uses hasn't been created yet when you see this loading state.

Setting no title in your theme isn't working because it maps to the window feature Window.FEATURE_NO_TITLE. This dominates over any other title window features you may request and once a feature is requested you can't un-request or remove it regardless of whether decor has been initialized yet.

As part of your theme, the title size is giving you predictable issues. Theme attributes can't be changed. However, which theme your activity is using can be changed before your window decor has been initialized. You can specify one theme in your manifest for the activity that will be used during loading and swap it out using setTheme on your activity. (Best place is probably in onCreate before setContentView, where you would otherwise request window features.)

Chances are the line below the title bar you're seeing is the android:windowContentOverlay - the drawable used to supply the drop shadow from the title bar over the content. On most devices the top edge of this shadow would probably appear as a line below the title bar area. You can set this to @null to get rid of the shadow entirely if you want.

adamp
  • 28,862
  • 9
  • 81
  • 69
  • Thank you, adamp! I solved it by using my 3rd solution and then setting the windowContentOverlay to null. :D – Arci Nov 27 '11 at 18:20
2

What I've done is set the following in my 'application' tag in my manifest.

android:theme="@android:style/Theme.NoTitleBar" 

And then, for each activity, I added

android:theme="@style/CustomTheme"
Paulina D.
  • 380
  • 3
  • 14
0

can you try to open application in full screen mode..then on load of application you can exit full screen.that way your title bar will not be visible while in full screen mode. This works in html.not sure if you can use this trick.

Pawan Kumar Jha
  • 118
  • 1
  • 11
  • Thanks for your reply. Can you please elaborate more on it? How do I load the application in full screen? I thought all applications in Android are in full screen? – Arci Nov 27 '11 at 17:55
  • i have implemented this trick only in html..thought it could be of use to you.you can work on this idea may be of some help. – Pawan Kumar Jha Nov 27 '11 at 18:00
  • I think I get what you are saying. I tried extending android:Theme.NoTitleBar.Fullscreen for my theme in XML, but I am getting a "You cannot combine custom titles with other title features" message when I try to set a custom title for my application in code. – Arci Nov 27 '11 at 18:01