使用XML的视图中的圆角

问题描述 投票:0回答:1

我正在尝试创建带有圆角的视图,但是我的XML在代码上存在以下错误:android:shape,android:color和android:radius。我真的很感激一个解决方案:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#ffffff" />
                <corners android:radius="20dp" />
            </shape>
        </item>
    </selector>```
xml android-layout rounded-corners
1个回答
0
投票

这类问题已经写了很多答案。如果您进行更多研究,您将轻松找到答案。但是,我仍在写答案。如果您发现它重复,请忽略。

   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    <solid android:color="@android:color/black" />
    <corners android:radius="20dp" />
    <stroke
            android:width="2dp"
            android:color="@android:color/white" />
    </shape>

使用以上代码创建新的资源文件,并将其设置为所有视图的背景。您可以期望背景如下图所示。

            android:background="@drawable/bg_rounded_rectangle_black"

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.