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.
To hide the Title Bar using the Android Manifest. xml file you need to set the Android theme to NoTitleBar like this: android:theme="@android:style/Theme. NoTitleBar">
The requestWindowFeature(Window. FEATURE_NO_TITLE) method of Activity must be called to hide the title.
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.xml
and 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 calling setTheme(android.R.style.Theme)
to go back to the default theme.
To elaborate just a bit on where in AndroidManifest.xml
this needs to be placed:
<application
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
Another solution could be set the tag:
android:label=""
In all the activities in the Manifest file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With