java - 使用 Glide 将图像添加到工具栏
问题描述
我正在创建一个应用程序,用户可以在其中从一系列头像中选择个人资料图像。头像图片 URL 存储在 Firebase 数据库中。当用户选择了一个图像时,我希望它显示在我的工具栏中。所以我认为这样的事情会起作用:
private void setToolBar(){
ref.child("Users").child(userID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
String profileimage = snapshot.child("OnavatarId").getValue(String.class);
String profileusername = snapshot.child("OnUsername").getValue(String.class);
profile_image = mtoolbar.findViewById(R.id.image);
Glide.with(MainActivity.this).load(profileimage).into(profile_image);
setSupportActionBar(mtoolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
工具栏 XML:
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_app_bar"
android:background="@color/design_default_color_primary">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</androidx.appcompat.widget.Toolbar>
但什么也没发生。
解决方案
profileimage
我认为您对图像的 url有问题。确保.error(R.drawable.error)
在加载照片时添加到您的滑行请求。
推荐阅读
- list - 机器人框架:字典没有关键错误
- thrift - 获取 Thrift 服务器的队列长度
- python - 如何使用 python 解决这个数学问题?
- sql - Postgres如何根据列保留最新副本并删除旧记录
- mysql - 填补数据中的月份和年份空白
- c# - 如何避免将用户 ID 添加到每个命令对象的代码重复?
- postgresql - 您可以向 postgresql 11 分区列表添加值吗
- java - 整数数据如何插入优先队列(序列无法理解)
- vba - 使用形状内的输入参数调用子过程
- python - 尝试使用 map 或 list comprehensions 展平列表列表时获得额外的 Nones 行,为什么?