简体   繁体   English

android - 如何从自定义操作栏的顶部和底部删除边距

[英]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 .我使用 Theme.AppCompat.Light 作为我的应用程序模板。

It is recommended to put the Toolbar layout xml in a separate file:建议将 Toolbar 布局 xml 放在单独的文件中:

<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然后将其包含在您的 main.xml 中

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

Also make sure to : app:contentInsetStart="0dp" this is the main issue for your magins.还要确保: app:contentInsetStart="0dp"这是您的主要问题。

In your ActionBar layout file give the android:heigth as match parent for the Parent View.在您的 ActionBar 布局文件中,将 android:heigth 作为父视图的匹配父项。 I also had a same issue with it.我也有同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AutoCompleteTextView - 如何从顶部和底部删除边距? - AutoCompleteTextView - How to remove margin from top and bottom? Android:从操作栏的自定义布局中删除左边距 - Android: remove left margin from actionbar's custom layout Android在Actionbar上删除边距/填充 - Android remove margin/padding at Actionbar Android:如何将listView与自定义actionBar的底部对齐? - Android: how to align listView to bottom of custom actionBar? Android应用程序顶部和底部的ActionBar - ActionBar on the TOP and BOTTOM on Android App 具有顶部和底部边距的自定义按钮 - Custom button with top and bottom margin 从Android TV中的BrowseFragment中删除上边距 - Remove top margin from BrowseFragment in Android TV 如何从ActionBar中删除顶部边框阴影 - How to remove top border shadow from ActionBar 自定义Android appcompat操作栏:如何删除v11 +设备上的底部边框 - Custom Android appcompat Actionbar: how to remove bottom border on v11+ devices 如何在Android中的ActionBar中删除左填充边距的额外空间? - How to remove the left padding margin extra space in the ActionBar in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM