即使背景未设置为白色,工具栏背景默认为白色

问题描述 投票:1回答:2

我在我的活动中使用工具栏,我没有设置任何类型的白色作为背景,但即使我没有设置任何背景,它仍然是白色的,我想要的是应该从工具栏中删除白色它应该加载我想要设置的背景请看看我的代码:

background_toolbar.xml:

<gradient
    android:angle="270"
    android:endColor="@android:color/transparent"
    android:startColor="#66000000"/>

toolbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:elevation="0dp"
    android:contentInsetLeft="0dp"
    android:contentInsetStart="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:contentInsetRight="0dp"
    android:contentInsetEnd="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp"
    app:layout_scrollFlags="scroll|enterAlways">
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="156dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:gravity="center"
            android:text="Table List"
            android:textColor="#679643"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.555" />

              <ImageView
            android:id="@+id/mfilter"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:src="@drawable/filter"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.975"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.652" />
    </android.support.constraint.ConstraintLayout>
            </android.support.v7.widget.Toolbar>

Styles.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#00000000</item>
    <item name="colorPrimaryDark">#0059ff</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

活动截图:

enter image description here

android android-layout android-toolbar
2个回答
0
投票

我想你错过了将android:background属性添加到工具栏中。

如果要使工具栏透明,可以尝试添加:

android:background="@null"

要么

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

如果你想设置一些特定的背景,那么:

android:background="@drawable/your_background_file"

它应该解决你的问题。

希望能帮助到你!


0
投票

这可能是因为您的样式在样式名称中包含一些不需要的值。请检查你的values-21。在我的例子中,由于values-21中的以下样式(在Android Studio中创建项目时生成),状态栏始终是透明的:

<resources>

  <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <!-- Unwanted attribute in my project -->
    <item name="android:statusBarColor">@android:color/transparent</item>
  </style>
</resources>
© www.soinside.com 2019 - 2024. All rights reserved.