【问题标题】:How to change a button's shape using xml or using java?如何使用 xml 或使用 java 更改按钮的形状?
【发布时间】:2011-10-04 05:12:39
【问题描述】:

我想做一个有形状的自定义按钮,怎么做?

【问题讨论】:

标签: android user-interface


【解决方案1】:

这是椭圆形形状的示例按钮。gradient 表示开始和结束颜色以及角度。椭圆形的角..试试这个..在按钮背景android:background="@drawable/sample"中提到这个xml的名称。将xml保存在drawable中。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#302226"
        android:endColor="#6D7B8D"
        android:angle="45"/>
    <padding android:left="6dp"
        android:top="6dp"
        android:right="6dp"
        android:bottom="6dp" />
    <corners android:radius="30dp" />

</shape>

还可以检查此link 以获取自定义按钮。

【讨论】:

  • 嗨,sureshpathi,如果答案对你有帮助,请考虑接受答案,另见meta.stackexchange.com/questions/16721/…
  • @suresh 如果我想让它看起来像一个箭头怎么办?有没有办法做到这一点?
【解决方案2】:

另一种查找不同形状按钮的方法

在xml中使用imagebutton作为

      <ImageButton
             android:id="@+id/imageButton1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:src="@drawable/shape_oval" />

Shape_oval 是一张我们可以从谷歌搜索中获取的图像,或者我们可以在油漆或 Photoshop 中绘制自己的图像。

【讨论】:

    猜你喜欢
    • 2019-12-20
    • 2016-02-21
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2011-02-19
    • 2020-01-26
    相关资源
    最近更新 更多