Home > Tricks & Tips > Colorizing the Title Bar

Colorizing the Title Bar


It’s very interesting if we can do some customizing over title bar on screen, like this:

Colorizing Title Bar

Colorizing Title Bar

Here the tricks:

package pete.android.study;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewParent;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // load title bar from Android layout
        TextView titleBar = (TextView)getWindow().findViewById(android.R.id.title);
        if (titleBar != null) {
            // set text color, YELLOW as sample
            titleBar.setTextColor(Color.YELLOW);
            // find parent view
            ViewParent parent = titleBar.getParent();
            if (parent != null && (parent instanceof View)) {
                // set background on parent, BRICK as sample
                View parentView = (View)parent;
                parentView.setBackgroundColor(Color.rgb(0x88, 0x33, 0x33));
            }
        }
    }
}

If you want to do some customization on default Android screen layout by re-construct the framework, then refer to this file: platforms/android-2.3.3/data/res/layout/screen.xml, whereas replace 2.3.3 by your version.

Have fun :D

 

Cheers,

Pete Houston

About these ads
Categories: Tricks & Tips Tags: , , ,
  1. praveen
    January 24, 2013 at 4:18 pm | #1

    I tried using setText() although there is no error title doesn’t change its the same as set in manifest. Then I removed the title for activity from manifest then the title of the app is being used as the title but the setText() content is totally ignored, although there are no errors or exceptions.

  2. praveen
    January 24, 2013 at 4:15 pm | #2

    How to change the title of the title bar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: