【问题标题】:Make Android Action Bar transparent使 Android 操作栏透明
【发布时间】:2016-04-19 15:00:02
【问题描述】:

我正在尝试使我的 AppCompatActivity 的操作栏透明。我正在寻找like this(来自this app)的东西。

我试过这样做:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

但它唯一能做的就是让视图隐藏在操作栏后面。

我该怎么做才能使文本和抽屉式导航按钮成为其上唯一可见的东西?

编辑: 这是我的 xml 布局

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            tools:context="my.package.name"
            android:id="@+id/relLayout">

            <!-- My views are here -->

        </RelativeLayout>

    </ScrollView>

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

【问题讨论】:

  • 你试过设置ActionBar的背景色吗?请显示您的 xml 布局。
  • @jonas.koeritz 我不确定如何使颜色不透明。我在xml布局中编辑。
  • @RuwankaMadhushan 你做到了!我将它与我之前的代码结合起来并使用颜色#00ffffff,它按预期完成了所有操作。谢谢!
  • 尝试像 #00000000 这样的 ARGB 值以获得完全透明。

标签: android android-actionbar android-appcompat


【解决方案1】:

对于未来的读者:

我通过将操作栏的颜色设置为完全透明的颜色来做到这一点,Color.TRANSPARENT。 这是我的代码:

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

 getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

【讨论】:

  • @AntónioPaulo 不,它会使应用程序崩溃,但 #00000000 有效
  • 我今天用了,我需要一个按钮来有透明背景。
  • @AntónioPaulo 我刚试了一下,它会抛出“无效颜色”异常
  • 也许可以在按钮中使用,因为它没有颜色。无论如何,自己找出答案很好。
  • @srv_sud 我可以在发布两天后接受我自己的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多