【问题标题】:Android XML: drawing StackOverflow's GraphicDesign's diamond/rhombus button with diamond/rhombus bordersAndroid XML:用菱形/菱形边框绘制 StackOverflow 的 GraphicDesign 菱形/菱形按钮
【发布时间】:2018-09-30 20:23:25
【问题描述】:

我想使用与此按钮相同的边框:(参见:https://graphicdesign.stackexchange.com/)。是否可以使用radius XML 属性(borderLeftTopRadius 等)来做到这一点?或者我必须使用一些图片吗?

【问题讨论】:

标签: android android-widget android-button android-styles


【解决方案1】:

只需创建一个可绘制资源文件:custom_button.xml

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="153.77dp"
android:height="41.33dp"
android:viewportWidth="153.77"
android:viewportHeight="41.33">

<path
    android:strokeColor="#e94b5a"
    android:strokeWidth="1"
    android:strokeMiterLimit="10"
    android:pathData="M 9.89 0.5 L 144.22 0.5 L 153.22 20.5 L 144.22 40.83 L 10.22 
40.83 L 0.55 20.5 L 9.89 0.5 Z" />
</vector>

然后把它作为你按钮的背景:

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ask question"
    android:textColor="#E94A5A"
    android:background="@drawable/custom_button"/>

截图:

Screenshot

【讨论】:

  • 我不知道path,谢谢!对这些改进有什么建议:支持点击按钮等材质输入事件,为按钮的点击表面着色?
【解决方案2】:

您可以使用向量来做到这一点。它在安卓工作室中可用。单击此链接以获取更多信息。 Add multi-density vector graphics

默认的 android xml 代码只会帮助您实现圆角和带有一些渐变的虚线边框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多