【问题标题】:How to bottom app bar background color in kitkat如何在 kitkat 中设置应用栏背景颜色的底部
【发布时间】:2019-08-01 08:11:58
【问题描述】:

我试图将底部应用栏背景颜色设置为透明。但在 kitkat 中,底部应用栏背景颜色未正确分配。在 kitkat 中,底部应用栏背景颜色为白色。如何根据需要设置底部应用栏背景颜色?

而且我不明白“背景”和“背景色调”。请让我知道这件事。

谢谢。

这是我的 xml 代码。

 <android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/circle_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/main_bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/view_transparent"
        app:fabAlignmentMode="center"
        app:fabCradleRoundedCornerRadius="2dp"
        app:hideOnScroll="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="@android:color/transparent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:background="@android:color/transparent"
                android:layout_toLeftOf="@id/empty_view"
                android:gravity="center_vertical">

                <LinearLayout
                    android:id="@+id/main_catalogue_btn"
                    android:layout_width="56dp"
                    android:layout_height="56dp"
                    android:layout_centerInParent="true"
                    android:background="@android:color/transparent"
                    android:gravity="center_vertical"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/catalogue_img"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        app:srcCompat="@drawable/ic_format_list_bulleted_white_24dp" />

                    <TextView
                        android:id="@+id/catalogue_txt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Catalogue"
                        android:textColor="@android:color/white"
                        android:textSize="12dp" />
                </LinearLayout>
            </RelativeLayout>

            <View
                android:id="@+id/empty_view"
                android:layout_width="68dp"
                android:layout_height="?actionBarSize"
                android:layout_centerInParent="true" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:background="@android:color/transparent"
                android:layout_toRightOf="@id/empty_view"
                android:gravity="center_vertical">

                <LinearLayout
                    android:id="@+id/main_info_btn"
                    android:layout_width="56dp"
                    android:layout_height="56dp"
                    android:layout_centerInParent="true"
                    android:background="@android:color/transparent"
                    android:gravity="center_vertical"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/main_info_img"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        app:srcCompat="@drawable/ic_info_white_24dp" />

                    <TextView
                        android:id="@+id/main_info_txt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:text="Info"
                        android:textColor="@android:color/white"
                        android:textSize="12dp" />
                </LinearLayout>
            </RelativeLayout>
        </RelativeLayout>
    </android.support.design.bottomappbar.BottomAppBar>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/main_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        app:borderWidth="0dp"
        app:elevation="1dp"
        app:fabSize="normal"
        app:layout_anchor="@id/main_bottom_app_bar"
        app:layout_anchorGravity="center"
        app:pressedTranslationZ="1dp"
        app:srcCompat="@drawable/ic_play_arrow_white_24dp" />
</android.support.design.widget.CoordinatorLayout>

color:view_transparent => #3b3737

【问题讨论】:

    标签: android colors background tint bottomappbar


    【解决方案1】:

    您应该使用app:backgroundTint。 BottomAppBar 有自己的背景,并且使用支持库的 backgroundTint 属性将色调应用于该背景,如果使用 android:backgroundTint ,则它将应用于来自 android 框架的一般视图背景,如 API 支持的 here 指定21(棒棒糖)。

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/main_bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/view_transparent"
        app:fabAlignmentMode="center"
        app:fabCradleRoundedCornerRadius="2dp"
        app:hideOnScroll="true">
    

    【讨论】:

      【解决方案2】:

      对我有用的是从代码中设置它

      bottomAppBar.setBackgroundResource(R.color.colorAccent);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多