droid
droid

Reputation: 41

Customized Title bar in android

I want to develop a title bar in android like this

  1. Home Button - Left aligned
  2. Application Title - At the center
  3. Image Icon - Right Aligned

I am not sure how to do it. I am a new user and hence not allowed to post the image here. Sorry for inconvinience.

Upvotes: 0

Views: 2064

Answers (2)

Rahul Patel
Rahul Patel

Reputation: 3843

There are two way for the change the title bar

1) Normal way,

you can Change the Title of each screen (i.e. Activity) by setting their Android:label

<activity android:name=".Hello_World"
     android:label="This is the Hello World Application">

2) if you want to Customize title-bar, i.e. you Want to put Image icon and custom-text, then following this LINK

Upvotes: 0

t0mm13b
t0mm13b

Reputation: 34592

To create a custom title bar, you need to do four things

  1. Set up a relative layout specifying TextView for left, center text, and a ImageView aligned in the centre.
  2. From the onCreate of the activity where the custom title is displayed, call requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
  3. Call setContentView as usual.
  4. Then you need to instruct that the layout of the custom title is to be put in place with the associated relative layout getWindow.setFeatureInt(Window.FEATURE_CUSTOMER_TITLE, R.layout.my_custom_title);

From there onwards, its a matter of obtaining the TextView and ImageView widgets via findViewById and calling the appropriate methods of the widget to suit the requirements.

Upvotes: 1

Related Questions