Monday, December 17, 2012

Android Custom Title Bar (PART-1)

Sometimes it is unwanted to having a title bar in our application activity screen , rather than the basic title bar we can use a custom title bar. for this we need to follow just two(2) steps.

1)  just use the line of code

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

 inside the onCreate() method


 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

      //Remove notification bar
    
        setContentView(R.layout.activity_main);

}


2) just use the given layout as a first element inside your main layout and do the appropriate changes.


<?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="35dip"
    android:background="@drawable/top_bar"
    android:gravity="center_vertical|center_horizontal|center"
    android:orientation="horizontal"
    android:weightSum="3"
   >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center"
        android:layout_weight="1"
        android:background="@drawable/menu_btn"
        android:text="Button" />

    <ImageView
        android:id="@+id/header"
          android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/kfc_connect" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center"
        android:layout_weight="1"
        android:background="@drawable/menu_btn"
        android:text="Button" />

</LinearLayout>





No comments:

Post a Comment