简体   繁体   English

使Android Action Bar透明

[英]Make Android Action Bar transparent

I'm trying to make my AppCompatActivity's Action Bar transparent. 我正在尝试使AppCompatActivity的操作栏透明。 I'm looking for something like this (from this app ). 我在找东西像这样 (从这个程序 )。

I've tried doing this: 我尝试这样做:

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

But the only thing it does is making views go behind the action bar. 但是它唯一要做的就是使视图位于动作栏的后面。

What can I do so that the text and the navigation drawer button are the only visible things on it? 我应该怎么做才能使文本和导航抽屉按钮是唯一可见的内容?

Edit: Here is my xml layout 编辑:这是我的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>

For future readers: 对于未来的读者:

I did it by setting the color of the action bar to a fully transparent color, Color.TRANSPARENT . 我是通过将操作栏的颜色设置为完全透明的颜色Color.TRANSPARENT Here is my code: 这是我的代码:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM