title: Android: Adding button to custom title bar
body: <p>I have created a custom title bar as shown in this example</p>
  
  <p><a href="http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/" rel="nofollow">http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/</a></p>
  
  <p>"A custom title bar" - half way down.</p>
  
  <p>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.</p>
  
  <p>Custom title bar is displayed as follows</p>
  
  <p><code>
   requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);<br>
   setContentView(R.layout.maintabhost);
   getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.headerbar_include);
  </code></p>
  
  <p>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)</p>
  
  <pre><code>    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();
  </code></pre>
  
  <p>I could just create another custom titlebar with the button already embedded, but a dynamic solution would be better.</p>
  
  <p>Cheers</p>