【问题标题】:Using Glide to add image to toolbar使用 Glide 将图像添加到工具栏
【发布时间】:2020-11-18 12:19:26
【问题描述】:

我正在创建一个应用程序,用户可以在其中从一系列头像中选择个人资料图片。头像图片 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>

但什么也没发生。

【问题讨论】:

    标签: java android imageview android-glide


    【解决方案1】:

    我认为您对图像的profileimage url 有疑问。请务必在加载照片时将.error(R.drawable.error) 添加到您的滑行请求中。

    【讨论】:

    • 添加 r.drawable.error 时出现无法解决错误?
    • 它可以是您的项目中的任何drawablebitmap,这表明您存在错误。
    • 看来我的数据快照返回的是空的..hmmm
    • 好的,所以我让它显示..但现在它出现全屏
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    相关资源
    最近更新 更多