So I am using the techniques in this thread to use a custom background for my titlebar. Unfortunately the framework places my layout inside a FrameLayout
(title_container
) which has padding as seen below.
(source: ggpht.com)
Is there anyway to remove the grey borders? The frame layout is defined in com.android.internal.R.id.title_container
, so accessing the frame by ID would be fragile.
I was struggling with this same issue and now I have the answer!
As you probably have seen several places, you need to create a themes.xml resource:
Note it is not often mentioned in the sites talking about custom title bars you need to select this theme at the view, activity, or application level. I do it at the application level by adding android:theme property to the application:
You also need a styles.xml to define that WindowTitleBackgroundStyle. Unlike the various versions of this file I have seen floating aroung the web, I have added one additional line to the file that sets the padding to 0 which gets rid of the padding you are complaining about:
There is a lenghty thread over on anddev.org that may be able to help you out
http://www.anddev.org/my_own_titlebar_backbutton_like_on_the_iphone-t4591.html
I have followed it and successfully created my own title bar which allows me to set the padding.
Xml for my title bar:
The above creates a small gray bar with text aligned to the right and left sides
I added the following padding item the AppTheme in styles.xml
The Application manifest uses that theme:
This resolved it for me.
As of 4.2 and ADT 21 when creating a default layout standard dimensions are added to the parent container:
Values are located in res/dimens.xml:
Either remove them from the parent or change the dimens.xml values to your desired values.
There is actually no need to use a custom layout to customise the background image. The following code in
theme.xml
will work:However, if you do actually want to use a custom title bar, then the following code will remove the margin:
title_bar_background
was set as the ID of the background image in the XML. I setandroid:scaleType="fitXY"
.As mentioned by dalewking, you can change the Manifest like this:
But it did not work for me until I added
to the activity it self like: