android - 如何将 BottomAppBar 的背景设置为位图?

标签 android material-design android-bottomappbar

下面我有一张位图,不是纯白的,有一些噪点:

enter image description here

如何设置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));

还有问题,看下面

enter image description here

中心圈应该像下面这样,但是现在周围都是背景位图: enter image description here

最佳答案

看起来这是不可能的。 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/

相关文章:

java - 更改 Color 对象的 Alpha

android - 如何用文本框中的值替换文档路径?

java - Android上的UDP打洞; UDP 服务器

android - 我可以为 API < 21 更改 android 中可绘制的单选按钮吗?

AndroidX BottomAppBar 导航图标颜色

android - 如何在 Android 11 中创建从图库中选择图像的 Intent ?

javascript - JS中如何检测MDC Snackbar是否关闭?

python - Django 高级过滤器在 django-material admin 主题中不起作用

kotlin - 如何隐藏某些片段中的底部导航栏?

android - 实现应用程序 :hideOnScroll for BottomAppBar in Android