Lollipop上的工具栏高度太大了。

5

我有一个应用程序实现AppCompat v7工具栏,Lollipop上的工具栏高度是Android<5.0的两倍。

更新:我现在会添加来自Kitkat和Lollipop的屏幕截图 工具栏xml如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:fitsSystemWindows="true"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
theme="@style/ThemeOverlay.AppCompat.ActionBar"
>

<LinearLayout
    android:padding="0dp"
    android:layout_margin="0dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right|center_vertical">

    <TextView
        android:id="@+id/action_bar_restaurant_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/restaurant_label_action_bar_margin_start"
        android:layout_weight="1"
        android:alpha="0"
        android:ellipsize="end"
        android:gravity="left"
        android:singleLine="true"
        android:textColor="@color/white"
        android:textSize="@dimen/restaurant_label_action_bar_font_size" />


    <ImageButton
        android:id="@+id/shuffle_restaurant"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="7dp"
        android:layout_weight="0"
        android:background="@color/transparent"
        android:scaleType="fitXY"
        android:src="@drawable/shuffle_button" />
</LinearLayout>
</android.support.v7.widget.Toolbar>

我的布局如下:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <include layout="@layout/toolbar" />
        <include layout="@layout/activity_content" />
    </FrameLayout>

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="fill_parent"
        android:layout_gravity="start"
        android:background="@color/list_background"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector"
        android:paddingTop="50dp" />

</android.support.v4.widget.DrawerLayout>

截图:

在此输入图片描述


你的工具栏高度是多少? - tyczj
这是问题的第一部分。 - Shehabic
尝试将您的工具栏中的 minHeight 替换为 height,以查看是否存在超出默认值的高度扩展内容。 - Pavel Dudka
我的意思是在Nexus 5上,它与模拟器相同,而不是S4。 - Shehabic
你是否在使用不同的样式来处理 values 和 values-v21? - Gabriele Mariotti
显示剩余6条评论
1个回答

12

好的,最终我找到了解决方案:

当你的状态栏是半透明的时候,你可能不想让你的工具栏移到状态栏下面,而是保持在原来“ActionBar”的位置上,你需要将其设置如下:

android:fitsSystemWindows="true"

但是,如果直接在工具栏上设置它,会导致我上面描述的问题,因此我将工具栏包装在内。

<FrameLayout />

并设置

android:fitsSystemWindows="true"

在FrameLayout上而不是工具栏上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接