Search code examples
androidtitlebar

Facing problem while using Title bar?


I am trying to insert a title bar with the following code. I try to keep the two buttons on it at left most and right most ends. But the buttons are not visible on the titlebar.
TextView is used as a title bar here and that is :

<TextView
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="CAMERA"
android:gravity="center_horizontal"
android:background="#4C7D7E"
>
</TextView>

code for buttons:

<

Button
android:id="@+id/save"
android:layout_width="144px"
android:layout_height="37px"
android:text="save"
android:layout_x="7px"
android:layout_y="388px"
>
</Button>
<Button
android:id="@+id/send"
android:layout_width="144px"
android:layout_height="37px"
android:text="send"

android:layout_x="158px"
android:layout_y="388px"
>
</Button>

Cant guess.Can any one help me

Thanks in advance


Solution

  • You should define a layout like this and set it as title bar.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout android:id="@+id/titlebar"
            android:layout_width="fill_parent" android:layout_height="80dp"
            xmlns:android="http://schemas.android.com/apk/res/android">
            <Button
             android:id="@+id/save"
             android:layout_width="144px"
             android:layout_height="37px"
             android:text="save"/>
    
            <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:id="@+id/titleText"
            android:text="right" />
    
            <Button
            android:id="@+id/send"
            android:layout_width="144px"
            android:layout_height="37px"
            android:text="send"
            android:layout_gravity="right"/>
    </LinearLayout>