1

I have a bitmap below,it's not pure white,has some noisy point:

enter image description here

How to set BottomAppBar's background as it,bitmap.xml is below,

<?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" />

in my activity_main.xml,I use it as below:

<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" />

but it not work,BottomAppBar's background not show the bitmap,is still pure white,I use the bitmap.xml successfully in other layout,but BottomAppBar not work.

I change xml's android:background="@drawable/bitmap" to java code:

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

but also has issue,look below

enter image description here

center circle should be like below, but arround now it's all background bitmap: enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
candrwow
  • 511
  • 5
  • 21

2 Answers2

1

Looks like this isn't possible. According to this:

The BottomAppBar internally handles its own background. This allows it to automatically cradle the FloatingActionButton when it is attached, but it also means that you shouldn’t call setBackground() or use the android:background attribute in xml. Instead, the app:backgroundTint attribute will allow you to set a tint.

Petter Hesselberg
  • 5,062
  • 2
  • 24
  • 42
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>

enter image description here