Make custom title view from defaults on Android
<p>How do I use androids default window title style to make my own similar <code>TextView</code>?</p>

<p>I have done a lot of guessing and made a TextView that has everything that
the default title bar has, except for the text shadow (and some padding/margins etc. I think).</p>

<p>Here's essentially what I've tried:</p>

<p>MainUI.xml</p>

<pre><code>protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
}
</code></pre>

<p>title_bar.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;TextView 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@+id/myTitle"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:textAppearance="@android:style/TextAppearance.WindowTitle"
  android:background="@android:drawable/title_bar"
  android:text="This is my new title" /&gt;
</code></pre>

<p><strong>Edit:</strong></p>

<p>I found some interesting related articles at <a href="http://labs.makemachine.net/2010/03/custom-android-window-title/" rel="nofollow">makemachine</a> and <a href="http://www.anddev.org/my_own_titlebar_backbutton_like_on_the_iphone-t4591.html" rel="nofollow">anddev</a>.</p>

<p>Although I don't like it, I copied some attributes from the implementation <a href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml;h=d7b654e49809cb97a35682754b1394af5c8bc88b;hb=HEAD" rel="nofollow">style.xml</a>.</p>

<p>Is there any way to avoid copying the attributes in this static way?</p>

<p>The following rendered almost perfect, the difference is in fact that the original did "cut" the first 2-3 pixels of the title shadow, while my <code>TextView</code> doesn't.</p>

<pre><code>&lt;TextView 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@+id/myTitle"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center_vertical"
  android:shadowColor="#BB000000"
  android:shadowRadius="2.75"
  android:singleLine="true"
  android:textAppearance="@android:style/TextAppearance.WindowTitle"
  android:background="@android:drawable/title_bar"
  android:text="This is my new title" /&gt;
</code></pre>

<p>It's also important to override the default android:windowTitleBackgroundStyle with a transparent color, because the default includes some padding etc. that you don't want to be wrapping your custom title bar.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
  &lt;style name="CustomTheme" parent="android:Theme"&gt;
    &lt;item name="android:windowTitleBackgroundStyle"&gt;@android:color/transparent&lt;/item&gt;
  &lt;/style&gt;
&lt;/resources&gt;
</code></pre>

<p>Remember to enable the theme in your <code>AndroidManifest.xml</code></p>
