【问题标题】:how to change background image on button at runtime in android如何在运行时在android中更改按钮上的背景图像
【发布时间】:2012-07-07 07:24:09
【问题描述】:

您好,我是一名新的 android 开发人员, 当我使用 R.drawable.image1 在运行时单击按钮时,我尝试更改背景图像, 然后我点击按钮显示另一个图像,如何更改图像名称, 但是图像名称声明的字符串数组,如何更改图像,使用

setBackgroundResource(R.drawable.images)

请任何人帮助我并解决我的问题

【问题讨论】:

  • 您要更换手机的walpaper吗?
  • 我的drawable文件夹中有很多图片,点击按钮从drawable文件夹更改图片
  • 是的,我知道,您想更改 walpaper 或图像视图内容吗?
  • 在我的应用程序中更改图像视图背景
  • 声明你的数组为整数数组

标签: android image dynamic background


【解决方案1】:
Integer[] imageIDs = {
            R.drawable.pic1,
            R.drawable.pic2,
            R.drawable.pic3,
            R.drawable.pic4,
            R.drawable.pic5,
            R.drawable.pic6,
            R.drawable.pic7                    
    };

并致电imageView.setImageResource(imageIDs[position]);

【讨论】:

  • String imgname="resources" + "pic1"; int resources=getResources().getIdentifier(imgname,"drawable","com.google") 可以显示特定图像
  • @mohamed 不,你不能那样做!!绝对错误 R.drawable.nameofpicture 是一个硬编码的整数,你可以在 gen/R.java 下找到
  • ,当我点击按钮调用一个类时,我设计了页面,例如我的可绘制文件夹中有很多图像,但我在该类中显示特定图像,返回并单击类我显示另一个图像,请帮助我 K_Anas
  • @mohamed 对不起,你能用简单的方式解释一下吗,我不明白你真正想要什么!!
猜你喜欢
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
  • 2011-02-02
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多