【问题标题】:Transparent action bar not being fully transparent. (Leaves weirdbox)透明操作栏不完全透明。 (留下奇怪的盒子)
【发布时间】:2016-09-17 05:29:39
【问题描述】:

我尝试将我为我的应用程序定制的操作栏设置为透明的。然而,它并没有完全透明,而是留下了一个奇怪的高程阴影:

http://puu.sh/rdYyb/04ce0147f6.jpg

栏的 XML:

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize" />

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


<android.support.design.widget.FloatingActionButton
    android:id="@+id/OverviewFAB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_alert" />

<RelativeLayout
    android:id="@+id/main_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

我的主题的样式 XML:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"></style>

我如何以编程方式尝试移除活动中的高程和背景:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbarlayout);
    appBarLayout.setElevation(0);
    toolbar.setElevation(0);
    appBarLayout.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
    toolbar.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));

但尽管如此,框(显示在链接中)仍然存在......我不确定发生了什么?有人看到我的代码有什么问题吗?

【问题讨论】:

  • 尝试把 app:elevation="0dp"
  • 什么也没发生 :(

标签: android android-actionbar transparency android-toolbar android-appbarlayout


【解决方案1】:

尝试放入应用栏

app:elevation="0dp"

工具栏中的这个

android:background="@android:color/transparent"

【讨论】:

  • 当我包含 app:elevation = "0dp" 时操作栏完全消失
  • 是的,但我有一个我希望用户能够看到的图标。目前图标不可见,但侧边导航菜单的功能仍然存在
  • 在您的工具栏中使用 app:popupTheme="@style/AppTheme.PopupOverlay" 。尝试运行并执行您的项目,然后它的更改将反映。
  • 是的,我在尝试您的建议时这样做了,但仍然看不到它
【解决方案2】:

我认为你需要使用 "android:alpha="0.5" 或使用 setAlpha() 方法。

【讨论】:

    【解决方案3】:

    我试过了,它对我有用,并将这四行添加到 xml 文件的工具栏小部件中。

    app:contentInsetEnd="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetRight="0dp"
                app:contentInsetStart="0dp"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多