繁体   English   中英

更改ImageButton的图像

[英]Change ImageButton's image

我想允许应用程序的用户从Drawable文件夹中选择一个图像并更改ImageButton的图像。
在我的应用程序中,我在Drawable文件夹中放置了一些图片。

这是可能的?

我的想法是:
1)有一个ImageButton
2)用户对setOnLongClickListener
3)从Drawable文件夹中选择图像并自定义图标。

谢谢大家!

请发布一些代码,无论如何,这是一个简单的解决方案:

//Execute on onItemLongClick
public void setSelectedDrawable(String imageResName, int selectedDrawableId) {

    Resources resources = context.getResources();
    Drawable drawable = resources.getDrawable(selectedDrawableId);
    if(drawable == null) resources.getIdentifier(imageResName, "drawable", "<package name>");           
    mImageButton.setImageDrawable(drawable);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM