【问题标题】:Lollipop Button with custom background color具有自定义背景颜色的棒棒糖按钮
【发布时间】:2015-09-13 15:48:26
【问题描述】:

我想使用具有自定义背景颜色的 Lollipop Button,例如下图中的按钮(强制停止和卸载)。当我使用

<Button
    android:background="#F44336"
    .... />

涟漪效应、阴影和高程消失了。而且我不能通过添加样式来使用两种不同的颜色。有没有办法实现它?

【问题讨论】:

  • 你设置了海拔吗?
  • 不,这是android sdk中包含的默认动画。
  • 所以你想要或不想要海拔和波纹?
  • 我想要那些效果。但是当我使用 android:background="" 时,这些效果就消失了。
  • 使用色调,而不是背景色

标签: android button


【解决方案1】:

您可以使用可绘制对象来创建波纹效果并设置背景颜色。

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="?android:colorControlHighlight">

    <!-- Note: <ripple> acts like a layer-list -->
    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <!-- This color is not displayed in any way -->
            <solid android:color="@android:color/black" />
        </shape>
    </item>

    <!-- This is the border -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#f0600000"/>
            <stroke android:width="1dp" android:color="#f00"/>
        </shape>
    </item>

 </ripple>

放入drawable 文件夹并将其设置为按钮的背景。

【讨论】:

  • 添加后,涟漪工作。像默认按钮一样的高程怎么样。
  • 一般来说,在棒棒糖之前的设备上没有连锁反应。它们不支持低级 RenderScript,这使得波纹和显示效果非常高效。
猜你喜欢
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多