vergil corleone
vergil corleone

Reputation: 1111

How to add button to title bar?

I am making an android app. I need to add a button to the title bar of an activity. I cannot put it in the action bar because of backward compatibility problems. I searched a lot but couldn't find a satisfactory solution for this. Thanks.

Upvotes: 0

Views: 592

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007544

Action bar requires API level 11 to work, my app's minimum is 9

Use a backport, like ActionBarSherlock, which offers action bars back to API Level 7. More importantly, it does so using an API compatible with the official action bar implementation, and so dropping ActionBarSherlock in a year or two (when you drop support for API Level 9-10) will be fairly easy. And, your app will have a consistent look and feel with other Android apps.

Upvotes: 3

Vincent van der Weele
Vincent van der Weele

Reputation: 13187

I needed something similar and created a custom title bar as follows:

  • Create a custom View class (I extended linearlayout)
  • Add this view to the layout xml of your activity, in the top
  • Hide the default bar, using requestWindowFeature(Window.FEATURE_NO_TITLE); (if I remember correctly, it is crucial to do this before setting the content view of your activity).

Upvotes: 0

Related Questions