材质设计:按钮不会采用主题颜色吗? [英] material design: buttons won't take theme color?

查看:72
本文介绍了材质设计:按钮不会采用主题颜色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扩展了material.light主题之后,设置了如下颜色:

After extending the material.light theme,and setting up the colors like this:

<resources>
    <!-- inherit from the material theme -->
    <style name="MiTemaMaterial" parent="android:Theme.Material.Light">
        <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="android:colorPrimary">#4DB6AC</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="android:colorPrimaryDark">#009688</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="android:colorAccent">#FFAB40</item>
    </style> </resources>

我得到了一个类似材料设计的导航栏,但是按钮之类的视图没有采用配色方案,而是默认显示.我想知道这是否是标准行为,因为在这里的设计指南中 http: //www.google.com/design/spec/components/buttons.html 似乎按钮使用了强调色.

I get a material desing-like navigation bar, but views like buttons don't take the color scheme and appear default. I'm wondering if this is standard behavior, since in the design guides like here http://www.google.com/design/spec/components/buttons.html it seems that butttons use the accent color.

我必须手动设置样式吗?

Do I have to style them manually?

推荐答案

是的,您需要自行设置按钮的主题.要提供采用原色的按钮,请在v21目录中使用一个可绘制背景的背景画,例如:

Yes, you need to theme the buttons yourself. To provide a button that takes on your primary color use a drawable in your v21 directory for your background such as:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?attr/colorControlHighlight">
    <item android:drawable="?attr/colorPrimary"/>
</ripple>

这将确保您的背景色为?attr/colorPrimary,并使用默认的?attr/colorControlHighlight(如果您愿意,也可以在主题中进行设置)来使用默认的波纹动画.

This will ensure your background color is ?attr/colorPrimary and has the default ripple animation using the default ?attr/colorControlHighlight (which you can also set in your theme if you'd like).

注意:您必须为低于v21的版本创建一个自定义选择器:

Note: you'll have to create a custom selector for less than v21:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/primaryPressed" android:state_pressed="true"/>
    <item android:drawable="@color/primaryFocused" android:state_focused="true"/>
    <item android:drawable="@color/primary"/>
</selector>

假设您想要默认,按下和聚焦状态的某些颜色.就我个人而言,我在选择过程中拍摄了涟漪的屏幕截图,并从中拉出了主要/焦点状态.

Assuming you have some colors you'd like for the default, pressed, and focused state. Personally, I took a screenshot of a ripple midway through being selected and pulled the primary/focused state out of that.

这篇关于材质设计:按钮不会采用主题颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆