简体   繁体   中英

android -how to remove margin from top and bottom of custom actionbar

I'm using a custom actionbar for my application . this is the code :

actionBar.setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setIcon(null);
    actionBar.setCustomView(mCustomView);
    Toolbar parent =(Toolbar) mCustomView.getParent();
    parent.setContentInsetsAbsolute(0, 0);

this is the result of this code , I 've margins from top and bottom :

在此处输入图片说明

How can I remove this margin ?

i'm using Theme.AppCompat.Light for my application template .

It is recommended to put the Toolbar layout xml in a separate file:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp" >

Then include it in your main.xml

<include layout="@layout/view_action_bar" />

Also make sure to : app:contentInsetStart="0dp" this is the main issue for your magins.

In your ActionBar layout file give the android:heigth as match parent for the Parent View. I also had a same issue with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM