如何使用xml或Java更改按钮的形状? [英] How to change a button's shape using xml or using java?

查看:62
本文介绍了如何使用xml或Java更改按钮的形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to make a custom button with shape, how to do this?

推荐答案

这是椭圆形形状的示例按钮.颜色以及角度.尝试使用此方法.在按钮背景 android:background ="@ drawable/sample" 中提及此 xml 的名称.将xml保存在可绘制.

This is the sample button which is of oval shape.. The gradient says the start n end color along with the angle. corners for the oval shape..Try this.. Mention the name of this xml in button background android:background="@drawable/sample".Save the xml in 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>

也请点击此链接以获取自定义按钮.

Also check this link for custom button.

这篇关于如何使用xml或Java更改按钮的形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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