han*_*789 8 android android-theme android-button android-styles material-components-android
我想更改活动切换按钮的颜色。但仅仅改变rippleColor 就会产生影响。我希望自定义活动按钮的背景颜色和文本颜色。
<style name="ToggleButtonGroupStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="rippleColor">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在下面的toggleButtonGroup中,我使用了上面的这种样式:
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/priority_btn_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentLeft="true"
app:selectionRequired="true"
app:singleSelection="true"
app:checkedButton="@+id/btn_one"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_one"
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:shadowColor="@color/project_text"
android:text="0" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!!" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="!!!" />
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
有人能给我提示一下这里的问题是什么吗?谢谢 :)
Gab*_*tti 13
选中按钮的背景颜色基于属性colorPrimary。
您可以使用:
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_one"
style="?attr/materialButtonOutlinedStyle"
android:theme="@style/ThemeOverlay.Custom.Button"
Run Code Online (Sandbox Code Playgroud)
和:
<style name="ThemeOverlay.Custom.Button" parent="">
<item name="colorPrimary">@color/....</item>
</style>
Run Code Online (Sandbox Code Playgroud)
或者您可以使用自定义样式:
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_one"
style="@style/ToggleButtonGroupStyle"
Run Code Online (Sandbox Code Playgroud)
和:
<style name="ToggleButtonGroupStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="backgroundTint">@color/custom_selector</item>
</style>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/..." android:state_checked="true"/> <!-- selected color -->
<item android:color="@android:color/transparent" android:state_checked="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2752 次 |
| 最近记录: |