0

I am designing an app which contains header title bar, I am using the following xml for creating header bar. but I am unable to show full width, if i use fill_parent it acts really weird. Any idea or any suggestions how to create a header title bar, increase decrease height. Thanks a lot.

window_title.xml lay out below. 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:padding="0px"
    android:layout_width="fill_parent"
    android:layout_height="60px"
    android:background="#323331">

    <ImageView 
        android:id="@+id/header" 
        android:src="@drawable/header"
        android:layout_width="fill_parent" 
        android:layout_height="60px"/>
</LinearLayout>

.java file 

        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.main);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
max
  • 3,047
  • 5
  • 20
  • 17

2 Answers2

0

use this if you dont need the defualt title. Thats all you need.

requestWindowFeature(Window.FEATURE_NO_TITLE);

Add this after your setContentView. nothing else is required.

blessanm86
  • 31,439
  • 14
  • 68
  • 79
  • I actually need a header for whole of my app removing the line would remove my header. Any other suggestions. – max Aug 22 '11 at 11:25
  • it seems you are trying to create a custom title bar. Hmm havent done that much. I usually create a separate xml layout file for the header. And for each xml layout for an activity i add the code . So it reuses the same xml header layout file. – blessanm86 Aug 22 '11 at 11:40
  • ok thats also a good way to do it...Thanks a lot for your help. – max Aug 22 '11 at 12:05
0

Your code is right, but you should use 9 patch drawable for ImageView source. Try, for example this line, and you'll see it works.

android:src="@android:drawable/dark_header"

dark_header it is 9 patch drawable from android sdk. You can find it in android-sdk/platforms/android-10/data/res/drawable-hdpi folder.

Update.
Clarifying what I mentioned in a comment. You should also create custom style for your title bar

<style name="LargeTitleTheme" parent="android:Theme">
    <item name="android:windowTitleSize">60dip</item>
    <item name="android:windowTitleBackgroundStyle">
      @android:drawable/dark_header
    </item>
</style>

and add it in AndroidManifest.xml

<activity 
  android:name=".TestActivity"
  android:label="@string/app_name" 
  android:theme="@style/LargeTitleTheme">
4e6
  • 10,696
  • 4
  • 52
  • 62
  • hi use 9 patch drawable for ImageView source, I dint get can you please give some more explanation or code. Thanks a lot. – max Aug 22 '11 at 12:11
  • As I said, your code logic is right, it should work. Also you should provide custom theme to the AndroidManifest. Take look at the [similar question](http://stackoverflow.com/questions/2086989/custom-title-with-image) – 4e6 Aug 22 '11 at 12:41