【问题标题】:Why does a transparent ActionBar have gaps to the left and right?为什么透明的ActionBar左右有间隙?
【发布时间】:2017-11-06 23:18:21
【问题描述】:

我想要一个带有透明 ActionBar 的类似画廊的 Activity。如果我给它一个透明的颜色,它会显示左右间隙。如果我给它一个纯色,它不会。这是为什么?我需要什么来删除它们?

我发现了一些类似的帖子,但所有给定的解决方案都不起作用或无法为我提供导致此问题的确切答案

activity_fullscreen_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout_fullscreen_image"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_image_fullscreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

app_bar_image_fullscreen.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:id="@+id/coordinator_lay"
    tools:context="com.myself.myapp.ImageFullScreenActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/appbar"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_image_fullscreen"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">


        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</android.support.design.widget.CoordinatorLayout>

v21\styles.xml(造成差距):

<resources>>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme.NoActionBar">
    <item name="colorPrimary">@android:color/transparent</item>
</style>

v21\styles.xml(不会造成间隙):

<resources>>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme.NoActionBar">
    <item name="colorPrimary">@color/myRed</item>
</style>

【问题讨论】:

  • 你有另一个布局包含这个工具栏布局吗?
  • 嗨 lbrahim,是的,我有。我刚刚将它添加到帖子中。谢谢!
  • 看起来问题不存在,无论如何问题不在工具栏或主题中,它是别的东西,仔细检查你的边距。
  • 那里我也看不到。我没有设置任何边距。我认为这是另一种现象,通过设置透明颜色变得可见......

标签: android android-actionbar transparent


【解决方案1】:

我在这篇文章的帮助下解决了这个问题:

when set app:elevation=“0dp” then hamburgermenu not showing to toolbar

所以我补充说:

 app:elevation="0dp"

到 AppBarLayout 和:

findViewById(R.id.appBar).bringToFront();

我在 onCreate 中的活动。但仍然不知道在我的情况下产生这种效果的内容是什么......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多