android - 使工具栏透明?

标签 android android-styles android-toolbar

我想让我的工具栏透明。
我找到了一些答案,但它们对我没有帮助。
我的工具栏是白色而不是透明的
这是我的工具栏:

<android.support.v7.widget.Toolbar
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:foxrey="http://schemas.android.com/apk/res-auto"
      foxrey:theme="@style/ActionBarThemeOverlay"
      foxrey:popupTheme="@style/ActionBarPopupThemeOverlay"
      android:id="@+id/toolbar_actionbar"
      android:background="@color/transparent"
      foxrey:titleTextAppearance="@style/ActionBar.TitleText.Inverse"
      android:layout_width="match_parent"
      android:layout_height="?actionBarSize" />

这是 ActionBarThemeOverlay:

<style name="ActionBarThemeOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
   <item name="android:textColorPrimary">#fff</item>
   <item name="colorControlNormal">?actionBarIconColor</item>
   <item name="colorControlHighlight">#3fff</item>
   <item name="android:windowActionBarOverlay">true</item>
   <item name="windowActionBarOverlay">true</item>

</style>

我也试过这个主题:

<style name="ToolbarTransparent" parent="Theme.AppCompat.Light">
   <item name="android:background">@color/tranp</item>
   <item name="background">@color/tranp</item>
   <item name="android:textColorPrimary">#fff</item>
   <item name="colorControlNormal">?actionBarIconColor</item>
   <item name="colorControlHighlight">#3fff</item>
   <item name="android:windowActionBarOverlay">true</item>
</style>

但它不起作用。

这是我现在拥有的:

enter image description here

我想得到这个:

enter image description here

最佳答案

你需要使用 Alpha 属性

View 的

Alpha 属性,介于 0(完全透明)和 1(完全不透明)之间的值。

XML 属性:

android:alpha

例子:

     <android.support.v7.widget.Toolbar
   xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:alpha="0"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

以编程方式:

setAlpha(float);

例子:

mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setAlpha(0);

Android Developers documentation

关于android - 使工具栏透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31693309/

相关文章:

android - 带有 CoordinatorLayout 的 NestedScrollView 内的 Recycler View

Android studio - 未找到应用程序的 Android 方面

android - 如何在运行时为按钮使用可绘制的 xml

android - 不同 api 的不同 styles.xml

android - 如何让旧的自定义 ActionBar 出现在新的 SDK 上?

android - 工具栏顶部的上下文叠加堆叠

android - 如何在工具栏的末尾设置一个图标

android - 应用程序进程被终止时不要打开最后一个 Activity

java - Listview order.runOnUiThread?

java - 发送信号。 PID : 6939 SIG: 9 with zxing QR code scanner