【问题标题】:Set border color for FloatingActionButton in support library在支持库中为 FloatingActionButton 设置边框颜色
【发布时间】:2015-11-10 01:23:12
【问题描述】:

在支持库中引入了FloatingActionButtonapp:borderWidth="2dp" 可以设置按钮的边框宽度,但是如何设置边框颜色呢?

我为那个porpuse创建了一个自定义的drawable,例如:

<item>
     <shape android:shape="oval">
         <solid android:color="@color/color1" />
         <stroke android:width="2dp" android:color="@android:color/white" />
     </shape>
</item>

并尝试使用 FloatingActionButton 的 android:backgroundapp:backgroundTint 属性来设置背景。他们都没有工作。请注意, app:backgroundTint 似乎只接受颜色而不是可绘制的

有人知道任何解决方法吗?

【问题讨论】:

    标签: android android-support-library floating-action-button


    【解决方案1】:

    你试过android:src属性吗? 试试这个

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/your_drawable"
        andriod:scaleType="center"  /> <!-- You need to scale your src. ->
    

    我希望它会起作用。

    编辑

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/your_icon" /> <!-- include your icon here -->
        <item>
            <shape android:shape="oval"> <!-- or rectangle -->
    
                <stroke
                    android:width="2dp"
                    android:color="@android:color/white" />
            </shape>
        </item>
    </layer-list>
    

    您可以在drawable 形状xml 中添加您的图标。并为您的图标添加边框并将其应用于FAB

    我在我的形状文件中添加了一个hdpi 图标,这就是我得到的结果。

    根据 Google 设计规范,实际可绘制尺寸应为 24dp

    【讨论】:

    • 不,那只是在 FloatingActionButton 的中心设置 drawable。为此,我有一个图标。我正在寻找自己的 FloatingActionButton 解决方案。
    • 我应该将这个drawable用于哪个属性? ( src, 背景, backgroundTint)
    • 你自己试过一次吗?或者你只是猜测它应该是一个解决方案?如果是,请在一个简单的示例中分享您的源代码,以确认您的提议。
    • 我告诉过你 android:src 只是集中图标。我猜你没有正确理解我在问什么。
    • 你真的让我实施了这个工厂。无论如何,我编辑了我的答案。您需要扩大工厂规模。 scaleType 应该是中心。我尝试了hdpi 图标。尝试调整图标大小。然后再告诉我,它是集中图标吗?
    猜你喜欢
    • 2016-01-05
    • 2013-09-16
    • 2015-08-13
    • 2015-11-29
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    相关资源
    最近更新 更多