Android – Change Title bar Text and Image

By -

In Android, mostly we see the activity with normal title bar i.e. Activity name in Title bar but here i am going to present how do we change the title bar text and title bar image (Background image, icon with text).

From my point of view, there are 2 ways to change the title bar text:

    1. Normal way

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

      Custom Title bar Text and Image

    But if you want to Customize title-bar in your way, i.e. Want to put Image icon and custom-text, then following code is running for me:

    main.xml

    titlebar.xml

    TitleBar.java

    public class TitleBar extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);

    if ( customTitleSupported ) {
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
    }

    final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
    if ( myTitleText != null ) {
    myTitleText.setText(“NEW TITLE”);

    // user can also set color using “Color” and then “Color value constant”
    // myTitleText.setBackgroundColor(Color.GREEN);
    }
    }
    }

    strings.xml

    The strings.xml file is defined under the values folder.

    Hello World, Set_Text_TitleBar!
    Set_Text_TitleBar

    #3232CD
    #FFFF00

  • Paresh Mayani

    Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

    Loading Facebook Comments ...
    Loading Disqus Comments ...