Android 6.0,Android Studio 3.5
在我的android项目中,在我的xml布局中:
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonStartSearchBluetooth"
style="@style/buttonEnableStyle"
android:layout_width="0dp"
android:layout_height="@dimen/button_height"
android:layout_margin="@dimen/button_margin"
android:onClick="onClickButtonStartSearch"
android:text="@string/start_search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
我的风格:
<style name="buttonEnableStyle" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:textColor">@color/text_color_states_materialbuttons</item>
<item name="backgroundTint">@color/color_states_materialbutton</item>
<item name="android:textAppearance">@style/byttonTexAppearanceStyle</item>
</style>
<style name="buttonClickStyle" parent="@style/Widget.MaterialComponents.Button">
<item name="android:textColor">@color/button_bg_color</item>
<item name="backgroundTint">@color/button_click_bg_color</item>
<item name="android:textAppearance">@style/byttonTexAppearanceStyle</item>
</style>
点击此按钮后,我想将样式从buttonEnableStyle
更改为buttonClickStyle
,并且处于运行状态。可以通过编程方式执行此操作吗?