AppCompatButton 和 buttonStyle
AppCompatButton and buttonStyle
我正在尝试让一些按钮使用 Material 设计风格(特别是 accentColor 着色)用于使用 AppCompat 库的 Android 4.4 设备。我在以下方面取得了成功:
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
style="@style/CompatButton"
android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
其中“@style/CompatButton”的父项为 "Widget.AppCompat.Button.Colored"。然而,我的一些按钮是相同的,但我没有在元素中声明样式,而是将样式附加为正在使用的主题中的默认样式 "buttonStyle":
<style name="AppTheme">
...
<item name="android:buttonStyle">@style/CompatButton</item>
<item name="colorAccent">@color/flow_accent</item>
...
</style>
和
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
这些按钮显示为默认的非 Material 样式。这似乎也发生在 ProgressBar 上。任何人都可以看出这有什么问题吗?是否有无需显式定义按钮样式的解决方法?
哎呀,那太蠢了。显然 ThemeOverlay 抹掉了之前的主题,包括 buttonStyle 定义。为了让它起作用,我们必须将 buttonStyle 添加回:
<style name="FlowOverlay" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:buttonStyle">@style/CompatButton</item>
</style>
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
android:theme="@style/FlowOverlay"/>
虽然这失去了我们最初想要的默认按钮样式的便利性。
我正在尝试让一些按钮使用 Material 设计风格(特别是 accentColor 着色)用于使用 AppCompat 库的 Android 4.4 设备。我在以下方面取得了成功:
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
style="@style/CompatButton"
android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
其中“@style/CompatButton”的父项为 "Widget.AppCompat.Button.Colored"。然而,我的一些按钮是相同的,但我没有在元素中声明样式,而是将样式附加为正在使用的主题中的默认样式 "buttonStyle":
<style name="AppTheme">
...
<item name="android:buttonStyle">@style/CompatButton</item>
<item name="colorAccent">@color/flow_accent</item>
...
</style>
和
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
这些按钮显示为默认的非 Material 样式。这似乎也发生在 ProgressBar 上。任何人都可以看出这有什么问题吗?是否有无需显式定义按钮样式的解决方法?
哎呀,那太蠢了。显然 ThemeOverlay 抹掉了之前的主题,包括 buttonStyle 定义。为了让它起作用,我们必须将 buttonStyle 添加回:
<style name="FlowOverlay" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:buttonStyle">@style/CompatButton</item>
</style>
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/continue_button"
android:id="@+id/continue_button"
android:layout_gravity="center_horizontal|bottom"
android:theme="@style/FlowOverlay"/>
虽然这失去了我们最初想要的默认按钮样式的便利性。