Creating A Custom Title Bar

 

This is a sample application which shows how to create a custom Title Bar in android. Last topic published on this forum is Create a Toggle Button.

Underlying Algorithm:

Basic description of algorithm in step by step form:

1.) Create a Project CustomTitleBar.
2.) Define a custom layout mytitle.xml in res/layout :

 

 

 

3.) Define colors.xml in res/values :

 

 

 

4.) Define themes.xml in res/values:

 

 

 

5.) Define styles.xml in res/values:

 

 

 

6.) Put the following code in AndroidManifest.xml:

 

 

 

7.) Run the application.

Steps to Create:

1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. CustomTitleBar. Enter following information:

Project name: CustomTitleBar
Build Target: Android 2.1
Application name: CustomTitleBar
Package name: com.app.CustomTitleBar
Create Activity: CustomTitleBar

On Clicking Finish CustomTitleBar code structure is generated with the necessary Android Packages being imported along with CustomTitleBar.java. CustomTitleBar class will look like following:

 

 

 

Output –The final output:

Leave a Comment:

12 comments
Alan Kleymeyer.com says January 17, 2012

Thanks for the great article. Exactly what I was looking for.

Isn’t the mytitle.xml missing the following line:

android:background=”@color/titlebackgroundcolor”

Reply
n says August 21, 2012

This seems very over complicated just to display a bar and title. Someone dropped the ball with this part of Android IMO.

Reply
Agustin says November 20, 2012

Its a Custom tittle, if you are looking for a simple actionbar look into android developer page. This article have the simplest way of doing a center, colored, custom, tittle, etc.

Reply
Vaibhav says January 3, 2013

Excellent tutorial ! Worked for me!:-)

Thanks a lot to the writer!

Cheers!

Reply
murat says February 6, 2013

very nice thanks.

Reply
Manal says February 9, 2013

Amazing!!! Really impressive, I was looking for sth like this for about a week. Finally I got it and got it right.

Reply
Anastassia says April 30, 2013

Thank you so much! It helped me out a lot 🙂

Reply
ramesh says June 15, 2013

can i run this application along with actionbar library.
i am getting error when i am implements with the aclinbarlibrary.

Reply
karthik says July 22, 2013

I am in need of a application can you help me for the code.
i want to send email in android without any intent. When i press the button named hai i want to send a mail with hai as subject.

kindly help.

Reply
mobile application development company says October 2, 2013

Right here is the perfect blog for everyone who would like to understand this topic.
You realize a whole lot its almost hard to argue
with you (not that I really will need to…HaHa).

You definitely put a brand new spin on a subject that’s been written about for many years.

Great stuff, just wonderful!

Reply
Andy Res says October 3, 2013

That’s nice, didn’t knew how to style the title bar.

Reply
Android Development @ Alan Kleymeyer's Blog says January 7, 2014

[…] Creating custom title bars […]

Reply
Add Your Reply