使用 Glide 将图像添加到工具栏

Using Glide to add image to toolbar

我正在创建一个应用程序,用户可以在其中从一系列头像中选择个人资料图片。头像图像 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) 添加到您的滑动请求中。