首页 > 解决方案 > 使用滑行动态加载图片到 ActionBar

问题描述

我想将图像加载Glide到我的ImageView那个是ActionLayout

这是我的菜单项

<item
    android:id="@+id/menu"
    android:title="Menu"
    app:actionLayout="@layout/menu_action_layout"
    app:showAsAction="always" />

这是我的动作布局

    <ImageView
        android:id="@+id/profileImageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="20dp" />
</FrameLayout>

这就是我加载它的方式

override fun onPrepareOptionsMenu(menu: Menu) {
    super.onPrepareOptionsMenu(menu)

    val menuItem = menu.findItem(R.id.menu)
    val rootView = menuItem.actionView
    val profileImageView = rootView.findViewById<ImageView>(R.id.profileImageView)
    val url = "https://www.dropbox.com/s/vauhd1q4nhoz7pn/ronaldo_profile.jpg?dl=1"
    Glide.with(this)
            .load(url)
            .into(profileImageView)
}

不幸的是,它不会加载图像。我已经尝试过使用普通的drawable并且它有效。

标签: androidandroid-actionbarandroid-toolbarandroid-glide

解决方案


您无法从 Dropbox 加载图像,您需要将“https://www.dropbox.com”更改为“ https://dl.dropboxusercontent.com ”,这样您的网址将如下所示:“ https:// dl.dropboxusercontent.com/s/vauhd1q4nhoz7pn/ronaldo_profile.jpg "


推荐阅读