我已将AppTheme的颜色设置为白色,但是在使用“材质按钮”和轮廓样式时,文本颜色显示为白色。
在styles.xml中可以做些什么吗?
style.xml文件
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorPrimary">@color/foopprimary_500</item>
<item name="colorPrimaryDark">@color/foopprimary_900</item>
<item name="colorAccent">@color/foopsecondary_500</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="fontFamily">@string/default_font</item>
<item name="colorOnPrimary">@color/foopsecondary_500</item>
<item name="colorSecondary">@color/foopsecondary_500</item>
<item name="colorOnSecondary">@color/foopprimary_500</item>
<item name="android:textColorPrimaryInverse">@color/foopsecondary_500</item>
</style>
color.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="foopprimary_50">#ffffff</color>
<color name="foopprimary_500">#ffffff</color>
<color name="foopprimary_900">#ffffff</color>
<color name="foopprimary_A400">#ffffff</color>
<color name="foopsecondary_300">#ff824d</color>
<color name="foopsecondary_500">#ff4d00</color>
<color name="foopsecondary_900">#ff2500</color>
<color name="foopsecondary_A100">#ffffff</color>
<color name="fooptextprimary_50">#e4e4e4</color>
<color name="fooptextprimary_100">#bcbcbc</color>
<color name="fooptextprimary_200">#909090</color>
<color name="fooptextprimary_300">#646464</color>
<color name="fooptextprimary_400">#424242</color>
<color name="fooptextprimary_500">#212121</color>
<color name="fooptextprimary_900">#0b0b0b</color>
<color name="fooptextprimary_A400">#ec0000</color>
</resources>
按钮的XML
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:text="@string/promote"
android:textAllCaps="true"
android:visibility="gone" />
输出是这样的
答案 0 :(得分:0)
您可以在MaterialButton
中覆盖原色:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:theme="@style/ThemeOverlay.Primary"
../>
具有:
<style name="ThemeOverlay.Primary" parent="">
<item name="colorPrimary">@color/....</item>
</style>
或者您可以使用以下方法定义自定义样式:
<com.google.android.material.button.MaterialButton
style="@style/Widget.App.Button.OutlinedButton"
android:layout_width="wrap_content"
.. />
具有:
<style name="Widget.App.Button.OutlinedButton" parent="@style/Widget.MaterialComponents.Button.OutlinedButton">
<item name="materialThemeOverlay">@style/ThemeOverlay.Primary</item>
</style>