1

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

Ron
  • 1,610
  • 15
  • 23
  • I was thinking I should move the image from the background to the foreground. Maybe this would avoid the issue with the text. – Ron Nov 27 '10 at 00:55

9 Answers9

3

If you are working on API level 11 or above than do this in your activity

final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);

Or you can do this by applying custom style to your activity like

  <style name="CustomWindowTitle" parent="android:TextAppearance.WindowTitle">
           <item name="android:visibility">gone</item>     
  </style>    

  <style name="MainTheme" parent="@android:Theme">    
     <item name="android:windowTitleStyle">
       @style/CustomWindowTitleText</item>   
 </style>

And then add it to your activity like

 <activity
            ......
 android:theme="@style/MainTheme"/>
Zain Ali
  • 15,535
  • 14
  • 95
  • 108
  • This answer solved my problem with removing title from Dialog themed activity that extends another activity's label. Thx – Ely Dantas Mar 28 '16 at 13:27
2

You can do it in Java, not resource xml, since the TextView on the title bar is determined programmatically by some lines in the Android Java source code.

You can hide the title bar's TextView in this way :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    root = (LinearLayout) decorView.getChildAt(0);
    FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
    TextView title = (TextView) titleContainer.getChildAt(0);
    title.setVisibility(View.GONE);
}
basicsharp
  • 446
  • 3
  • 8
  • 2
    He wants the titlebar just not the text so setTitle(""); in your activity – Nathan Schwermann Nov 27 '10 at 03:35
  • setTitle("") works but apparently the label is loaded by the system and shown for a brief moment before setTitle("") hides it. – Ron Nov 27 '10 at 14:42
  • Actually, the only way to remove the text properly from the App's titlebar is to set the "app_name" to "" in the manifest... – Ron Nov 28 '10 at 03:17
  • 1
    nasty side effect - name of the app in the app list is also "" - NOT good – Ron Nov 29 '10 at 02:59
  • 3
    add an empty label to the activity in the manifest ... this hides the title text – Ron Nov 29 '10 at 04:25
1

Add this to your manifest

<application  android:label="bla bla"
              android:icon="@drawable/bla bla"
            --->  android:theme="@android:style/Theme.NoTitleBar">
Perception
  • 79,279
  • 19
  • 185
  • 195
Bom
  • 11
  • 1
1

I'm not sure, but you can also try to declare your activities without label in manifest.

<activity android:name="...">
Tima
  • 12,765
  • 23
  • 82
  • 125
  • I actually do. This does not prevent the title (editable by setText()) to be shown... – Ron Nov 27 '10 at 14:41
  • Ok, another suggestion, what if you would give a title, but an empty one?! – Tima Nov 27 '10 at 19:45
  • see my last comment on the previous answer: Actually, the only way to remove the text properly from the App's titlebar is to set the "app_name" to "" in the manifest... – Ron Nov 28 '10 at 23:09
  • the best solution is to declare the activity WITH AN EMPTY LABEL in order to hide the title text... – Ron Nov 29 '10 at 04:25
  • I've meant an empty label as well. Now we know, it works :) congratulations – Tima Nov 29 '10 at 08:16
0

Set your theme to a custom theme for the activity. The theme would look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme.Black.OptionalActionBar" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowNoTitle">false</item>
        <item name="android:windowActionBar">true</item>
        <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    </style>

    <style name="MyActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:displayOptions">showHome</item>
    </style>

    <style name="OptionalVisibility">
        <item name="android:visibility">invisible</item>
        <item name="android:height">1dp</item>
    </style>

</resources>

The ActionBarStyle overrides the behavior of the action bar. Notice I set the style to the holo actionbar and then change the displayOptions to showHome. This will only show the home icon. You can also set it to showTitle which will only show the text. Or both showHome|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.

Michael Stoner
  • 1,341
  • 1
  • 14
  • 27
0
android:theme="@android:style/Theme.NoTitleBar"> 

adding this in your manifest file works..

Srikanth Pai
  • 926
  • 3
  • 17
  • 30
0
android:label=""

add this to manifest

Qazi Firdous
  • 117
  • 1
  • 9
0

Try to set an empty custom titlebar with an empty layout.

Boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);    
    setContentView(R.layout.listviewoffers);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebarlayout);
ThePikeman
  • 151
  • 3
0

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(""); inside onCreate().

That's it! Hope this helps!

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143