Skip to content Skip to sidebar Skip to footer

Android Can't Remove Padding Around Custom Title Bar

I'm adding a custom img to the header title but no matter what I do I still have a small gap on each side of the img (also shown in this question) Here is the xml in my strings.xml

Solution 1:

you can override default padding by applying custom theme like

<stylename="customTheme"parent="android:Theme"><itemname="android:windowTitleBackgroundStyle">@style/WindowTitleStyle</item></style><stylename="WindowTitleStyle"><itemname="android:padding">0px</item></style>

This will remove default padding from custom title bar.

Solution 2:

It turns out I had to modify the background color of the title container itself :)

privatevoidsetNavigationAndTitle() {
        setTitle("Random Title");
        ViewGroupdecorView= (ViewGroup) this.getWindow().getDecorView();
        LinearLayoutroot= (LinearLayout) decorView.getChildAt(0);
        FrameLayouttitleContainer= (FrameLayout) root.getChildAt(0);
        titleContainer.setBackgroundColor(Color.BLUE);
        TextViewtitle= (TextView) titleContainer.getChildAt(0);
        title.setTextSize(20);
        title.setGravity(Gravity.CENTER);
        title.setBackgroundColor(Color.BLUE);
}

Solution 3:

As of 4.2 and ADT 21 when creating a default layout standard dimensions are added to the parent container:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" >

</RelativeLayout>

Values are located in res/dimens.xml:

<!-- Default screen margins, per the Android Design guidelines. --><dimenname="activity_horizontal_margin">16dp</dimen><dimenname="activity_vertical_margin">16dp</dimen></resources>

Either remove them from the parent or change the dimens.xml values to your desired values.

Solution 4:

you could try making the setPadding values to negitive numbers

Post a Comment for "Android Can't Remove Padding Around Custom Title Bar"