开发者

set image on a button in android?

开发者 https://www.devze.com 2023-01-15 21:59 出处:网络
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

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.setBackgroun开发者_Go百科dDrawable(d);


Why not use

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


You can use the "Image Button" it's better for you ,,, and the code like this :

final ImageButton next = (ImageButton) findViewById(R.id.Button02) ;
Drawable d = Drawable.createFromPath("@drawable/finalarrow1");
next.enter.setImageDrawable(d);
0

精彩评论

暂无评论...
验证码 换一张
取 消