android操作栏和标签之间存在差距。为什么?

时间:2015-07-07 15:03:09

标签: android android-layout

我为具有Tabview的操作栏创建了自定义布局。但是动作栏和黑色标签之间存在差距。请看下面的图像。我使用的主题是Theme.AppCompat.Light.DarkActionBar 目标SDK:19 请帮忙。

style.xml如下:

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

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" />

2 个答案:

答案 0 :(得分:1)

立即尝试使用工具栏 ActionBar 弃用。你可以拥有比ActionBar更多的功能。

此处为example,您需要使用

答案 1 :(得分:0)

我记得以前遇到过这个麻烦。尝试在xml中添加contentInsets。

<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"    
/>