Android studio 为什么不能直接在draw able里面用stroke和corner

安卓应用开发
为什么不能直接在draw able里面用stroke和corner,默认只有item这个选项,在室友的电脑上是可以的

img

本意是想给我的用户名设置边框

img

这个是运行的错误提示

img

版本号是这些 都是自动生成的没动过

img


img

你应该这么写

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true">
        <shape android:shape="rectangle">
            <corners android:radius="2.41dp" />
            <stroke android:width="1dp" android:color="#1989FA" />
            <solid android:color="#ffffff" />
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle">
            <corners android:radius="2.41dp" />
            <stroke android:width="0.5dp" android:color="#1989FA" />
            <solid android:color="#ffffff" />
        </shape>
    </item>
</selector>

如果可以预览,那就是缓存问题,之前的代码是正确的,加了item这个标签,然后你编译后有了缓存,AS直接从缓存预览。
不允许在selector下直接加stroke和corners,因为这不是它的合法子属性。
你不必纠结为什么不能预览,这本身就是不规范的。你写代码还是按照规范来

假设它是指Android Studio中的"Drawable"资源文件。在这种情况下,Stroke和Corner属性并不是Drawable资源文件中可以直接使用的属性。Stroke属性通常用于为视图添加边框,而Corner属性用于将视图设置为圆角。

color="#FBFBFB"