如何在 kitkat 中底部应用栏背景颜色
How to bottom app bar background color in kitkat
我正在尝试将底部应用栏背景颜色设置为透明。但在 kitkat 中,底部应用栏背景颜色未正确分配。在 kitkat 中,底部应用栏背景颜色为白色。如何根据需要设置底部应用栏背景颜色?
而且我不明白 'background' 和 'backgroundTint'。请让我知道这件事。
谢谢。
这是我的 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>
颜色:view_transparent => #3b3737
你应该使用 app:backgroundTint
。
BottomAppBar 有自己的背景,使用支持库的 backgroundTint 属性将色调应用到该背景,如果使用 android:backgroundTint
则它将应用到来自 android 框架的一般视图背景 here 由 API 21 (LOLLIPOP) 支持。
<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">
对我有用的是从代码中设置它
bottomAppBar.setBackgroundResource(R.color.colorAccent);
我正在尝试将底部应用栏背景颜色设置为透明。但在 kitkat 中,底部应用栏背景颜色未正确分配。在 kitkat 中,底部应用栏背景颜色为白色。如何根据需要设置底部应用栏背景颜色?
而且我不明白 'background' 和 'backgroundTint'。请让我知道这件事。
谢谢。
这是我的 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>
颜色:view_transparent => #3b3737
你应该使用 app:backgroundTint
。
BottomAppBar 有自己的背景,使用支持库的 backgroundTint 属性将色调应用到该背景,如果使用 android:backgroundTint
则它将应用到来自 android 框架的一般视图背景 here 由 API 21 (LOLLIPOP) 支持。
<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">
对我有用的是从代码中设置它
bottomAppBar.setBackgroundResource(R.color.colorAccent);