android操作栏和选项卡之间有一个间隙。为什么?

android操作栏和选项卡之间有一个间隙。为什么?,android,android-layout,Android,Android Layout,我已经为带有Tabview的actionbar创建了自定义布局。但在操作栏和黑色标签之间有一个间隙。请看下图。我正在使用theme.AppCompat.Light.darkaActionBar 目标SDK:19 请帮忙 style.xml如下所示: <!-- Application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <

我已经为带有Tabview的actionbar创建了自定义布局。但在操作栏和黑色标签之间有一个间隙。请看下图。我正在使用theme.AppCompat.Light.darkaActionBar 目标SDK:19 请帮忙

style.xml如下所示:

<!-- Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarSize">36dip</item>
    </style>

36浸
activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/MyCustomTabLayout"
    app:tabBackground="@android:color/holo_orange_dark"
    app:tabIndicatorColor="@android:color/holo_green_dark"
    app:tabTextColor="@android:color/white"
    app:tabSelectedTextColor="@android:color/black"/>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    android:background="@android:color/white" />

自定义操作栏

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_dark">
<Spinner
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/spinnerActionBar" />


尝试使用工具栏,因为操作栏现在是弃用的。您可以拥有比ActionBar更多的功能


这里好像你需要使用

我记得以前遇到过这个问题。尝试在xml中添加ContentInset

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...
    app:contentInsetStart="0dp"
    app:contentInsetEnd="0dp"    
/>

考虑使用新工具栏而不是自定义视图。无论如何,尝试使用
wrap\u content
作为自定义视图的高度和宽度,而不是
match\u parent