Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This <a href="http://www.anddev.org/my_own_titlebar_backbutton_like_on_the_iphone-t4591.html" rel="noreferrer">thread</a> will get you started with building your own title bar in a xml file and using it in your activities</p> <p><strong>Edit</strong></p> <p>Here is a brief summary of the content of the link above - This is <strong>just</strong> to set the color of the text and the background of the title bar - no resizing, no buttons, just the simpliest sample </p> <p><em>res/layout/mytitle.xml</em> - This is the view that will represent the title bar</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:text="This is my new title" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@color/titletextcolor" /&gt; </code></pre> <p><em>res/values/themes.xml</em> - We want to keep the default android theme and just need to change the background color of the title background. So we create a theme that inherits the default theme and set the background style to our own style.</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;@style/WindowTitleBackground&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p><em>res/values/styles.xml</em> - This is where we set the theme to use the color we want for the title background</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;style name="WindowTitleBackground"&gt; &lt;item name="android:background"&gt;@color/titlebackgroundcolor&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p><em>res/values/colors.xml</em> - Set here the color you want</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;color name="titlebackgroundcolor"&gt;#3232CD&lt;/color&gt; &lt;color name="titletextcolor"&gt;#FFFF00&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>In the <em>AndroidMANIFEST.xml</em>, set the theme attribute either in the application (for the whole application) or in the activity (only this activity) tags</p> <pre><code>&lt;activity android:name=".CustomTitleBar" android:theme="@style/customTheme" ... </code></pre> <p><em>From the Activity (called CustomTitleBar) :</em></p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload