I am using a titlebar with a background image in my android app.
values/custom_styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">@drawable/titlebar</item>
</style>
<style name="Theme.MyCustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@style/TitlebarBackgroundStyle</item>
<item name="android:windowTitleSize">45dp</item>
</style>
</resources>
layout/titlebar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical">
<ImageView
android:id="@+id/header"
android:src="@drawable/titlebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/Theme.MyCustomTheme">
This works pretty well so far.
The only thing I'd like to do now is to hide the text on the titlebar ...
I tried:
<item name="android:textSize">0dp</item>
but with no luck. Is there any way to set the transparency or some other property that would allow me to see the background image but not the text?
thanks for your thoughts Ron
Fortunately the way is too simple (I guess you do have a custom layout for your title)
If you don't know to do how please take a look: How to Create Custom Window Title in Android
Hiding the default title text is one line of code. Just write
setTitle("");
insideonCreate()
.That's it! Hope this helps!
If you are working on API level 11 or above than do this in your activity
Or you can do this by applying custom style to your activity like
And then add it to your activity like
add this to manifest
Set your theme to a custom theme for the activity. The theme would look like this:
The ActionBarStyle overrides the behavior of the action bar. Notice I set the style to the holo actionbar and then change the
displayOptions
toshowHome
. This will only show the home icon. You can also set it toshowTitle
which will only show the text. Or bothshowHome|showTitle
. If you leave it blank,<item name="android:displayOptions"></item>
then the text and icon will go away all together.NOTE: I know this will work for 3.0 (api 11) and above...I am not certain if it will work for lower API levels.
I know this is years old...but posting for others who encounter this problem.
I'm not sure, but you can also try to declare your activities without label in manifest.
Try to set an empty custom titlebar with an empty layout.