Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The little gap to the left/right is added by the framework since the default <code>windowTitleBackgroundStyle</code> in the <a href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml" rel="nofollow">standard theme</a> used a <a href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/title_bar.xml" rel="nofollow">9-patch drawable</a> with that <a href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable-hdpi/activity_title_bar.9.png" rel="nofollow">padding</a>. Here's an example on how to override this:</p> <p>In AndroidManifest.xml, add an <code>android:theme</code> for your Activity:</p> <pre><code>&lt;activity android:theme="@style/MyCustomTitlebar" android:label="Custom Titlebar" android:name=".CustomTitlebar" /&gt; </code></pre> <p>Then define the custom theme somewhere in your resources (for example in res/values/themes.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;resources xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;style name="MyCustomTitlebar" parent="@android:style/Theme"&gt; &lt;item name="android:windowTitleBackgroundStyle"&gt;@style/MyBackground&lt;/item&gt; &lt;/style&gt; &lt;style name="MyBackground"&gt; &lt;item name="android:background"&gt;@drawable/background&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>Since we move the background to the style, we can modify your mytitle.xml layout to the following:</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_width="match_parent" android:layout_height="match_parent" android:text="custom title bar" /&gt; </code></pre> <p>You might need to adjust either your background (so it has some padding if it's a 9-patch) or just set the padding in the mytitle.xml layout (using paddingLeft/Right/Top/Bottom).</p>
 

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