下面我有一张位图,不是纯白的,有一些噪点:
如何设置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));
还有问题,看下面
最佳答案
看起来这是不可能的。 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.
关于android - 如何将 BottomAppBar 的背景设置为位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54124260/