使用glide向工具栏添加图像

lx0bsm1f  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(477)

嗨,伙计们,我正在创建一个应用程序,用户可以从选择的头像中选择一个配置文件图像。化身图像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>
但什么都没发生谁能帮帮我吗

xmq68pz9

xmq68pz91#

我想你有问题 profileimage 图像的url。一定要加 .error(R.drawable.error) 你的滑翔请求时加载照片。

相关问题