Android_长方形带圆角边框的按钮背景

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 内部颜色 -->
    <solid
        android:color="#ffffff" />
    <!-- 边缘线条颜色 -->
    <stroke
        android:width="1dp"
        android:color="#37B047" />
    <!-- 圆角的幅度 -->
    <corners
        android:topLeftRadius="4dip"
        android:topRightRadius="4dip"
        android:bottomLeftRadius="4dip"
        android:bottomRightRadius="4dip" />

</shape>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Android长方形色盘的实现方法: 1.在res/drawable文件夹下创建一个selector.xml文件,代码如下: ```xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false"> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#FFD2D2" /> <corners android:radius="1dp"/> <gradient android:angle="0" android:startColor="#FF3333" android:endColor="#F8F8F8" android:type="linear" /> </shape> </item> </selector> ``` 2.在布局文件中添加自定义的RectangleColorSelectorView,代码如下: ```xml <com.example.colorselfdefinedemo.RectangleColorSelectorView android:id="@+id/self_view" android:layout_width="fill_parent" android:layout_height="wrap_content" /> ``` 3.创建RectangleColorSelectorView类并继承View类,代码如下: ```java public class RectangleColorSelectorView extends View { private Paint mPaint; private int mWidth; private int mHeight; public RectangleColorSelectorView(Context context) { super(context); init(); } public RectangleColorSelectorView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public RectangleColorSelectorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mWidth = getWidth(); mHeight = getHeight(); LinearGradient linearGradient = new LinearGradient(0, 0, mWidth, 0, new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED}, null, Shader.TileMode.CLAMP); mPaint.setShader(linearGradient); canvas.drawRect(0, 0, mWidth, mHeight, mPaint); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值