【发布时间】:2021-05-06 17:30:27
【问题描述】:
我有一个带有集中图标+文本的按钮,当某些事件发生时,我需要更改 app:icon 和 android:text 属性。我知道有setText()的方法可以改文字,但是有没有改图标的方法?
XML:
<Button
android:id="@+id/bottom_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/default_margin"
android:layout_marginVertical="@dimen/bottom_bar_content_vertical_margin"
android:backgroundTint="@color/light_green"
android:text="@string/next"
android:textAllCaps="false"
app:icon="@drawable/ic_baseline_next_plan_24"
app:iconGravity="textStart" />
这是一个在适当事件后调用的函数,我需要更改该函数中的图标。 icon 和 text 是所需的可绘制对象和字符串的 id:
private void setBottomButton(int icon, int text) {
button.setText(getString(text));
}
【问题讨论】:
标签: java android android-button