Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4550596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:31:04+00:00 2026-05-21T16:31:04+00:00

I have created a custom title bar as shown in this example http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/ A

  • 0

I have created a custom title bar as shown in this example

http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/

“A custom title bar” – half way down.

On some activities I would like to place a button on the right hand side of the titlebar (same as facebook app). I have attempted to add a button to the view as follows, but it doesn’t appear.

Custom title bar is displayed as follows


requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.maintabhost);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.headerbar_include);

Attempting to add button as follows. The button will eventually be an ImageButton and aligned to right of custom titlebar-if I get it working. (just realised I’ve too many layoutparams now, but this isnt affecting the button display)

    LinearLayout layout = (LinearLayout) findViewById(R.id.headerbar);
    Button searchButton = new Button(this);
    searchButton.setText("info");

    LayoutParams layoutParams = new LinearLayout.LayoutParams
    (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    searchButton.setLayoutParams(new LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    layout.addView(searchButton, layoutParams);
    layout.invalidate();

I could just create another custom titlebar with the button already embedded, but a dynamic solution would be better.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:31:05+00:00Added an answer on May 21, 2026 at 4:31 pm

    First of all, thanks for the link to my blog. Second, let me see if I can’t answer that for you. One of the reasons you’re having trouble adding another button when you want to add a button is that in that example I left you with no way of retrieving the Title Bar View through the usual channels. Hence, let’s fix it (and potentially let me write another blog post this coming weekend.)

    Starting with the xml file, add an id attribute:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="horizontal"
        android:id="@+id/title_complex">
        <!-- Stuff -->
    </LinearLayout>
    

    and here’s code to show you how to get that button in there within your Activity (you’ll have to add all the flair later):

    LinearLayout layout = (LinearLayout) getWindow().findViewById(R.id.title_complex);
    layout.addView(new Button(this));
    

    and if you take a look, there’s a non-descript button in the Title Bar (like I said, you’ll have to add your own flair):

    Title Bar with another button

    Due note, however, that I can’t guarantee that the button will remain or won’t remain on subsequent Activities. I haven’t investigated it yet but this should get you started. And if you have any more questions, feel free to ask them here (more eyeballs) or on my blog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have a similar problem with this ( https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination ) and can't really figure
I have created a flexible navigation bar in my app that will show custom
I have created a custom button using this code setup : function(ed) { ed.addButton('Tittle',
As per the title, I have created a custom control. On a certain button
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
I have created a custom dialog for Visual Studio Setup Project using the steps
If have created a custom role within SqlServer which I added to the db__denydatareader
I have created a simple Asp.Net custom control which automatically combines all the correct
I have created a small flash CS4 project that has a few custom components

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.