1

我在下面有一张位图,它不是纯白色的,有一些嘈杂的地方

在此处输入图像描述

如何设置BottomAppBar的背景,bitmap.xml如下,

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bg"
    android:tileModeX="repeat"
    android:tileModeY="repeat" />

在我的 activity_main.xml 中,我使用它如下:

<com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottom_app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@drawable/bitmap"
            app:fabAlignmentMode="center"
            app:fabAnimationMode="scale"
            app:navigationIcon="@drawable/ic_settings" />

但是它不起作用,BottomAppBar的背景不显示位图,仍然是纯白色,我在其他布局中成功使用了bitmap.xml,但是BottomAppBar不起作用。

我将 xml 的 android:background="@drawable/bitmap" 更改为 java 代码:

bottomAppBar.setBackground(getResources().getDrawable(R.drawable.bitmap));

但也有问题,看下面

在此处输入图像描述

中心圆应该如下所示,但现在周围都是背景位图: 在此处输入图像描述

4

2 回答 2

1

看起来这是不可能的。据此

BottomAppBar 在内部处理自己的背景。这允许它在附加 FloatingActionButton 时自动放置它,但这也意味着您不应调用 setBackground() 或在 xml 中使用 android:background 属性。相反, app:backgroundTint 属性将允许您设置色调。

于 2019-01-10T08:58:01.670 回答
0
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity" >





<!-- Content -->
<include
    layout="@layout/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:fabAlignmentMode="center"
        app:navigationIcon="@drawable/ic_menu"
        app:menu="@menu/actions"
        android:animateLayoutChanges="true" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        style="@style/Widget.MaterialComponents.FloatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:backgroundTint="@color/colorAccent"
        app:tint="@android:color/white"
        app:srcCompat="@drawable/ic_record"
        app:layout_anchor="@id/bar" />

    <FrameLayout
        android:id="@+id/bottom_drawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="16dp"
        app:behavior_hideable="true"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigation_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/rounded_sheet"
            app:itemIconTint="?attr/bottom_bar_ic_tint"
            app:elevation="0dp"
            app:menu="@menu/primary"/>
    </FrameLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

在此处输入图像描述

于 2021-03-30T05:40:13.443 回答