在操作过程中想要动态改变button的drawableTop属性
通过button的setCompoundDrawables方法来设置,不过在设置Drawable对象的时候需要调用setBounds方法设置一下
<Button
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:drawableTop="@drawable/home_active"
android:onClick="show"
android:text="首页"
android:textColor="#00FFFF"
/>// Two = getResources().getDrawable(R.drawable.star_active);
// Two.setBounds(0, 0, Two.getMinimumWidth(),Two.getMinimumHeight());
// btn2.setCompoundDrawables(null, Two, null, null);方向 左上右下
动态修改Button图标
本文介绍如何在Android应用中动态地更改按钮(button)的顶部图标(drawableTop),通过使用setCompoundDrawables方法结合设置Drawable边界来实现这一功能。
404

被折叠的 条评论
为什么被折叠?



