gpt4 book ai didi

android - Material 按钮中定义的样式与 AppTheme 不兼容

转载 作者:行者123 更新时间:2023-12-03 16:50:43 25 4
gpt4 key购买 nike

I chnaged the Apptheme attributes according to the new material guidelines, due to this my material button which I have used in all my project lost their theme colors.



我尝试通过将默认设置设为其父级并让它们更改其主要和次要颜色来制作自定义样式。

按钮的 XML 文件
<com.google.android.material.button.MaterialButton
android:id="@+id/bs_create_business"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:text="@string/create_business"
android:textAllCaps="true"
app:backgroundTint="@color/browser_actions_bg_grey" />

样式.xml
    <style name="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/foopprimary_500</item>
<item name="colorPrimaryDark">@color/foopprimary_900</item>
<item name="colorAccent">@color/foopsecondary_500</item>
<itemname="android:windowBackground">@android:color/white</item>
<item name="fontFamily">@string/default_font</item>

<item name="colorSecondary">@color/foopsecondary_500</item>
<item name="colorOnSecondary">@color/foopprimary_500</item>
</style>

我的输出是这样的:
enter image description here

最佳答案

更改 Widget.MaterialComponents.Button.OutlinedButton 中的颜色风格只需使用类似的东西:

  <style name="MyButton" parent="Widget.MaterialComponents.Button.OutlinedButton" >
<!-- Border color -->
<item name="strokeColor">@color/stroke_color_selector</item>
<!-- Text color -->
<item name="android:textColor">@color/text_color_selector</item>
<!-- Background color -->
<item name="backgroundTint">@color/text_btn_bg_color_selector</item>
</style>

enter image description here

选择器的默认值为:

描边颜色:
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_checked="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_checked="false"/>
</selector>

文字颜色:
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.00" android:color="?attr/colorPrimary" android:state_checkable="true" android:state_checked="true" android:state_enabled="true"/>
<item android:alpha="0.60" android:color="?attr/colorOnSurface" android:state_checkable="true" android:state_checked="false" android:state_enabled="true"/>
<item android:alpha="1.00" android:color="?attr/colorPrimary" android:state_enabled="true"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>

背景:
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.08" android:color="?attr/colorPrimary" android:state_checked="true"/>
<item android:color="@android:color/transparent" android:state_checked="false"/>
</selector>

关于android - Material 按钮中定义的样式与 AppTheme 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57882421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com