简体   繁体   English

可绘制的android使顶部边缘以不同的颜色倒圆

[英]Drawable android to make top edge rounded with different color

How to make top-left with light gray rounded color and top-right with dark gray and bottom-edges with white rounded, 如何使左上角具有浅灰色的圆形颜色,以及如何使右上角具有深灰色的颜色和底边具有白色圆形的颜色,

Currently i am getting bottom-edges white rounded but want to change the color of top left and right rounded with different color. 目前,我正在将底边的白色四舍五入,但想要更改左上角和右上角的颜色以其他颜色。

I tried : 我试过了 :

<?xml version="1.0" encoding="utf-8"?>


<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item >
        <shape android:shape="rectangle"  >
            <corners android:bottomLeftRadius="3dip"
                android:bottomRightRadius="3dip"
                android:topRightRadius="3dip"
                android:topLeftRadius="3dip"
                />
            <stroke android:width="1dip" android:color="@color/white" />
            <gradient android:angle="-90" android:startColor="@color/white" android:endColor="@color/white" />
        </shape>

    </item>
</selector>

Image Link : 图片链接:

1: Define layout_bg.xml in drawables: 1:在可绘制对象中定义layout_bg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip"       
 android:bottom="0dip"/>
</shape>

2: Add layout_bg.xml as background to your layout 2:将layout_bg.xml作为背景添加到布局中

android:background="@drawable/layout_bg"

Try this code..I hope you useful 试试这个代码..我希望你有用

Try this : 尝试这个 :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#959595" />
            <stroke
                android:width="0dp"
                android:color="#959595" />
            <corners android:radius="3dp" />
            <gradient
                android:angle="0"
                android:endColor="@android:color/black"
                android:startColor="@android:color/darker_gray" />
            <padding
                android:bottom="0dp"
                android:left="3dp"
                android:right="3dp"
                android:top="3dp" />
        </shape>
    </item>

    <item>
        <shape>

            <solid android:color="#FFFFFF" />
            <stroke
                android:width="0dp"
                android:color="#FFFFFF" />
            <corners
                android:topLeftRadius="3dp"
                android:topRightRadius="3dp" />
            <padding
                android:bottom="3dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>


    <item>
        <shape>
            <solid android:color="#FFFFFF" />
            <stroke
                android:width="0dp"
                android:color="#c2c2c2" />
            <corners
                android:radius="3dp"
                />
            <padding
                android:bottom="3dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>

if you want something like this 如果你想要这样的东西 在此处输入图片说明

then follow my code test.xml 然后按照我的代码test.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#959595" />
            <stroke
                android:width="0dp"
                android:color="#959595" />
            <corners android:radius="3dp" />
            <gradient
                android:angle="-90"
                android:endColor="@android:color/black"
                android:startColor="@android:color/darker_gray" />
            <padding
                android:bottom="3dp"
                android:left="3dp"
                android:right="3dp"
                android:top="3dp" />
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle"
            >
            <solid android:color="#fff" />
        </shape>
    </item>
</layer-list>

I applied my drwable to a textview background 我将drwable应用于textview背景

<TextView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:background="@drawable/test"
    android:padding="10dp"
    android:text="@string/hello_blank_fragment" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM