I made a custom title bar for my app which works. However, when the app first loads, the app name is displayed in the title bar for a moment before my text appears. How do I stop this from happening?
I set my custom title bar in my main activity here:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
mytitle.xml is where I set my text:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTitle"
android:text="my text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearance"
/>
My title bar background doesn’t flash, just the text.
Thanks.
Basic explanation: when launching an application, to respond as quickly as possible to the user, Android first shows a “preview” window of the app before it even starts bringing up its process. It does this by taking the information available in the app’s
AndroidManifest.xmland creating a window that looks like however an empty activity for it would appear. Thus, you should set the theme in the manifest to something that matches as closely as possible what your actual UI looks like.For the case of a custom title, there isn’t much you can do, because what the title will look like depends on what your code actually does and none of your code is running yet. The best you can probably do is use
android:theme="@android:style/Theme.NoTitleBar"so that the preview window doesn’t try to show any title bar at all… of course in your activity you will need to clear this out by callingsetTheme(android.R.style.Theme)to go back to the default theme.To elaborate just a bit on where in
AndroidManifest.xmlthis needs to be placed: