TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

android Button动态修改背景图

Laughing博主
2020-12-06
/
0 评论
/
2,004 阅读
/
45 个字
/
百度已收录
12/06
本文最后更新于2020年12月06日,已超过1383天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

我们在布局文件中,设置Button的背景图片时,一般是通过如下方式

<ImageButton
    android:id="@+id/buttonListTopMenuSave"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/detail_save"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    />

如果我们需要动态设置图片,可以通过如下方式

buttonListTopMenuSave = findViewById(R.id.buttonListTopMenuSave);
buttonListTopMenuSave.setBackgroundResource(R.drawable.detail_ok);
buttonListTopMenuSave.setOnClickListener(this);
安卓
朗读
赞(1)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/app/android-button-dynamically-modifies-background-image.html(转载时请注明本文出处及文章链接)

评论 (0)
  1. Laughing 闲逛
    Android · QQ Browser

    再次强调,垃圾评论不会通过

    2018-04-19 回复