Custom Title Bar in ANDROID

By | March 29, 2012

Hi all….

Today in this post I will show you how to give a custom layout for the titleBar in ANDROID.
You can place almost anything inside a title using your custom layout.

Now go on and create a fresh project and copy this code into the main java file

package pack.coderzheaven;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;

public class CustomTitleDemo extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);

        if (customTitleSupported) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
            TextView tv = (TextView) findViewById(R.id.tv);
            tv.setText("CoderzHeaven");

            ProgressBar titleProgressBar = (ProgressBar) findViewById(R.id.PB);
            //titleProgressBar.setVisibility(ProgressBar.GONE);
        }
    }
}

Now create a new xml file and name it custom_title.xml and copy the following code to it.

.

        

Note: remember to have images mentioned here in the drawable folder.

Now the strings.xml file where the color is defined.

Hello World, Custom Title Bar from CoderzHeaven#ffffff#000000#2554C7#347C2C#ff9900#FF00FF#a020f0#778899#C11B17#FFFF8C#b0e0e6#2F1700#7D2252

Atlast the AndroidManifest.xml file.

Custom TitleBar in ANDROID

Custom TitleBar in ANDROID

Please leave your valuable comments if you found this post useful………

Leave a Reply

Your email address will not be published. Required fields are marked *