我用这个风格改变背景色的我Button
:如何使用AppCompat设置禁用的按钮颜色?
<style name="AccentButton" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">@color/colorAccent</item>
<item name="android:textColor">@color/white</item>
</style>
而且在布局:
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_login_login_button"
app:theme="@style/AccentButton"/>
它的工作原理。但是当我在Button
上拨打setEnabled(false)
时,它保持相同的颜色。我如何管理这种情况?
定制'ThemeOverlay.AppCompat.Light'名为'AccentButton'对我来说是最清楚的方式。只有一个'colorButtonNormal'时,'Button'被禁用时'accentColor'与白色混合看起来是正确的。谢谢! – Alexandr
而不是单独应用彩色样式,简化是将此样式声明移动到AccentButton主题中:将其定义为主题的buttonStyle。这样,每个按钮声明只需添加一个附加属性。 –
@JoeBowbeer - 正如[选择按钮样式博客文章](https://medium.com/google-developers/choosing-a-button-style-with-purpose-and-intent-35a945e228d3)中提到的,凸起颜色按钮不一定是整个主题的标准,因此将其设置为基本'buttonTheme'可能有点多。 – ianhanniballake