6

I made a custom title bar. In the title bar are two imageviews next to each other and one textview beneath it. It works fine but I just see the top of the textview. So I think the title bar get cropped at the underside. Does somebody know how to set the height of a custom title bar? EDIT: My custom title bar:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="45dip"
    android:orientation="vertical"
    android:id="@+id/header_root"> 
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ImageView
    android:id="@+id/header_image"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:src="@drawable/header_image"
    />

<ImageView
    android:id="@+id/options"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:layout_margin="-8dip"
    android:layout_toRightOf="@+id/header_image"
    android:src="@drawable/options" />

</RelativeLayout>
<TextView 
    android:text="Vissenencyclopedie"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="15dp"
    android:id="@+id/titel"
    android:layout_marginTop="-7dip"
    />
</LinearLayout>  
Simon
  • 2,328
  • 6
  • 26
  • 30

3 Answers3

8

Use style:

 <style name="CustomTheme" parent="@android:style/Theme.Light">
    <item name="android:windowTitleSize">30dp</item>
</style>

And add to manifest:

 <activity
        android:name=".MainActivity"
        android:theme="@style/CastomTheme" >
 </activity>
Tim
  • 1,606
  • 2
  • 20
  • 32
  • Correct solution! If you want to go further and add a custom background color/image, see here: http://stackoverflow.com/a/2285722/1208581 – sulai Dec 13 '12 at 11:24
  • Thank you. spelling android:theme="@style/CastomTheme" -> android:theme="@style/CustomTheme" – dsharew Oct 02 '14 at 07:39
1

I am assuming that the title bar is within some sort of layout, so what you can do is to set the height of the layout, for example:

android:height="30dp"

You can also provide padding for the textviews, for example:

android:paddingBottom="10dp"

This should make sure that the text is displayed. Hope this helps.

kibria3
  • 289
  • 1
  • 4
  • 21
  • Well, it doesn't. I already tried this. When I look at the graphical layout of the custom title bar it shows the title bar correctly. But when I run the app on the emulator and go to the activity with this custom layout, the textview is cropped. – Simon Jun 02 '12 at 18:19
0

I assume the problem lies in the android:layout_height="45dip" you specified for your outer LinearLayout. Replace that line with android:layout_height="wrap_content" and I suppose this will solve your problem.

Arun George
  • 18,352
  • 4
  • 28
  • 28