在android中创建带有圆角的按钮 [英] Create Button with rounded corners in android

查看:35
本文介绍了在android中创建带有圆角的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个如上图所示的按钮.最初我的想法是创建一个 9 补丁并将其设置为按钮背景.但是因为这是一个普通的按钮,我想我们可以在不使用任何图像的情况下以某种方式绘制它.

I'm trying to create a button which looks as in the image above. Initially my idea was to create a 9 patch and set it as the button background. But since, this is a plain button, i think we can somehow draw this without using any images.

按钮背景色为#0c0c0c边框颜色为#1a1a1a文字颜色为#cccccc

The button background color is #0c0c0c The border color is #1a1a1a The text color is #cccccc

我在 SO 上发现了一个类似的问题,但这会产生渐变 -
Android - 按钮边框

I found a similar question on SO but that creates a gradient -
Android - border for button

推荐答案

Android 开发者指南对此有详细的指南:Shape Drawbables.

The Android Developer's Guide has a detailed guide on this: Shape Drawbables.

您也可以简单地从您提供的链接中删除 gradient 元素:

You could also simply remove the gradient element from the link you provided:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#1a1a1a" />
</shape>

这篇关于在android中创建带有圆角的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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