在Android的一个按钮设置图像?按钮、图像、Android

2023-09-05 00:49:46 作者:浅水流沙

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

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

解决方案

为什么不使用

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

android中怎么实现图片成一个圆形排列

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);