【发布时间】:2019-01-23 08:18:28
【问题描述】:
此刻,我觉得有点愚蠢。 这是我的问题: 我实际上想为某些按钮应用不同的样式,与我的默认按钮样式不同。
我的styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="CustomTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/CustomTheme.ActionBarStyle</item>
<item name="cardViewStyle">@style/CustomTheme.CardViewStyle</item>
<item name="buttonStyle">@style/CustomTheme.StandardButton</item>
</style>
<...>
<style name="CustomTheme.StandardButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">@drawable/ripple_button</item>
<item name="android:tint">@color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.ConfirmButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">@drawable/ripple_button_confirm</item>
<item name="android:tint">@color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.CancelButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">@drawable/ripple_button_cancel</item>
<item name="android:tint">@color/white</item>
<item name="android:elevation">8dp</item>
</style>
</resources>
事实上,我尝试了很多关于继承 CustomTheme.ConfirmButton 和 CustomTheme.CancelButton 的事情。
CustomTheme.StandardButton 的变化:形状的颜色。
ripple_button.xml 是橙色的。
然后,我创建了另外两个波纹按钮,第一个是红色(取消按钮),第二个是绿色(确认按钮)。
默认情况下,应用<item name="buttonStyle">@style/CustomTheme.StandardButton</item>。
但是,在我的活动中,即使我为按钮声明了特定主题,默认样式也是唯一应用的样式。 注意:这两个按钮在这些活动中始终可见。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_confirm_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/lbl_confirm"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/btn_cancel_reset"
android:layout_marginBottom="8dp"
style="@style/CustomTheme.ConfirmButton"/>
<Button
android:id="@+id/btn_cancel_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/lbl_cancel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/btn_confirm_reset"
android:layout_marginBottom="8dp"
style="@style/CustomTheme.CancelButton"/>
</android.support.constraint.ConstraintLayout>
我尝试为每个按钮手动应用“默认”StandardButton 主题(然后从我的styles.xml 中删除<item name="buttonStyle">@style/CustomTheme.StandardButton</item> 行,但我仍然得到相同的行为:我所有的按钮总是橙色(并且使用 StandardButton主题)。
所以我想知道我失败的地方/我不明白的地方,或者即使有可能。
如果一个平静的灵魂有一个想法,一些提示,我将不胜感激(我可以用法国精酿啤酒感谢我的英雄)。
祝您有美好的一天,感谢您的阅读。
【问题讨论】: