我一直试图使用以下代码在按钮上设置图像,但它似乎不起作用...我认为我做错了是我正在使用的图像的路径,但我尝试了不同的路径,它不会工作...我已将我的图像复制到res文件夹中的drawable文件夹...我在这里做错了什么?
final Button next = (Button) findViewById(R.id.Button02) ;
Drawable d = Drawable.createFromPath("@drawable/finalarrow1");
next.setBackgroundDrawable(d);
Run Code Online (Sandbox Code Playgroud)
Kan*_*hen 27
为什么不用
final Button next = (Button) findViewById(R.id.Button02);
next.setBackgroundResource(R.drawable.finalarrow1);
Run Code Online (Sandbox Code Playgroud)
Oub*_*aan 11
你可以使用"图像按钮",它更适合你,,,以及像这样的代码:
final ImageButton next = (ImageButton) findViewById(R.id.Button02) ;
Drawable d = Drawable.createFromPath("@drawable/finalarrow1");
next.enter.setImageDrawable(d);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42133 次 |
| 最近记录: |