透明的Android Lollipop中的操作栏和状态栏

8
我正在尝试创建这个界面: enter image description here 但实际结果是这样的: enter image description here
  • 状态栏透明,我们可以看到我的背景图片:OK
  • 操作栏不透明:NOK
这是我使用的活动主题代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- inherit from the material theme -->
    <style name="MaterialAppDetailTheme" parent="android:Theme.Material.Light">

        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowActionBarOverlay">true</item>

        <!-- enable window content transitions -->
        <item name="android:windowContentTransitions">true</item>

        <!-- specify shared element transitions -->
        <item name="android:windowSharedElementEnterTransition">
            @transition/change_image_transform</item>
        <item name="android:windowSharedElementExitTransition">
            @transition/change_image_transform</item>

        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowTranslucentStatus">true</item>

    </style>
</resources>

你正在使用actionbar还是toolbar? - Pedro Oliveira
@PedroOliveira actionBar - wawanopoulos
3个回答

6
您可以像这样将工具栏颜色更改为透明:
mToolbar.setBackgroundColor(getResources().getColor(android.R.color.transparent));

您可以在XML中更改其背景:

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

如果您正在使用ActionBar:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

如果您不使用ActionBarActivity,请使用getActionBar()

结果:

enter image description here


1
如果他在主题/布局xml中使用fitSystemWindow,他需要将额外的marginTop添加到状态栏的大小中。否则,状态栏底部线将位于导航图标上,这看起来不好。 - Nikola Despotoski
我想他已经解决了这个问题,因为他描述的唯一问题是他的操作栏不透明。当前屏幕只是我建立的一个东西,只是为了展示效果。 - Pedro Oliveira
是的,只是作为预防措施。 :) - Nikola Despotoski

2

使用这种样式:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@color/my_text_color</item>
    <item name="colorPrimary">@android:color/transparent</item>
    <item name="windowActionBarOverlay">true</item>
</style>

1

对于API大于等于21的情况,在主题中添加以下代码:

<item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item>

不要忘记添加

android:fitsSystemWindows="true"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接