I am making a custom titlebar using the following xml file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTitle"
android:text="custom title bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" />
And inside my activity’s onCreate() i have the following code:
public class CustomTitleBar extends Activity {
/** Called when the activity is first created. */
@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);
}
}
The title bar is coming no problem.The image i am setting as background(the name of image is background too as u can see in above xml) is also coming.But the problem is in both right and left side of the image there is remaining a little gap i.e the image is not covering the whole width of parent though the layout_width has been set to “fill_parent”.
Anyone any idea.plz help.
The little gap to the left/right is added by the framework since the default
windowTitleBackgroundStylein the standard theme used a 9-patch drawable with that padding. Here’s an example on how to override this:In AndroidManifest.xml, add an
android:themefor your Activity:Then define the custom theme somewhere in your resources (for example in res/values/themes.xml):
Since we move the background to the style, we can modify your mytitle.xml layout to the following:
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).