how to add button to custom title bar in android

3 1,231

Add button to custom title bar

in this tut you will learn how you add button to title bar in android.

button to title bar in android

main activity.java

in main activity oncreate method we will call requestWindowFeature method for custom title bar later we will setcontentview for main activity and at the end with getwindows method we will set our custom title bar XML layout to main activity title bar.

 

activity_main.xml

custom_title_bar.xml

in custom title bar we have just one simple button to assign this button in mian layout title bar for share button

Download button custom title bar source code

 

Comments

comments

  1. ebad ahmed says

    Thanks for writing this code
    It’s working fine
    i have a query
    i want to change the color of title bar from grey to any other how can we change it in your code?
    sorry for my bad english

    1. Ebi says

      its done….

      1. ebad ahmed says

        Thanks for your help.
        This code is working,
        But unfortunately it is not working perfect as you can see in picture that this color does not cover all the title bar,border of title bar is not converting in it
        kindly look into this issue
        thanks for your help

Leave A Reply

Your email address will not be published.