在Android的一个按钮设置图像? [英] set image on a button in android?

查看:142
本文介绍了在Android的一个按钮设置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用下面的code上设置一个按钮图像,但它似乎并没有工作......我认为我做错了是图像的我用,但我的路尝试了不同的路径,它不会工作...我抄我的形象在资源文件夹中的文件夹绘制...我究竟做错了什么?

 最后按钮旁边=(按钮)findViewById(R.id.Button02);
 绘制对象D = Drawable.createFromPath(@绘制/ finalarrow1);
  next.setBackgroundDrawable(四);
 

解决方案

为什么不使用

 最后按钮旁边=(按钮)findViewById(R.id.Button02);
next.setBackgroundResource(R.drawable.finalarrow1);
 

i have been trying to set a image on a button using the following code but it doesn't seem to work...i think what i am doing wrong is the path of the image i am using but i tried different paths and it wont work...i have copied my image to the drawable folder in res folder...what am i doing wrong here??

final Button next = (Button) findViewById(R.id.Button02) ;
 Drawable d = Drawable.createFromPath("@drawable/finalarrow1");
  next.setBackgroundDrawable(d);

解决方案

Why not use

final Button next = (Button) findViewById(R.id.Button02);
next.setBackgroundResource(R.drawable.finalarrow1);

这篇关于在Android的一个按钮设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆