如何在 android 中为文本视图实现此自定义形状?

How can i achieve this custom Shape in android for a textview?

如何通过 Android 形状可绘制对象在 Android 中实现如下形状:

您可以简单地创建一个自定义形状并将其设置为您的 TextView:

的背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

    <solid android:color="#00ff00" />

    <corners
        android:bottomRightRadius="4dp"
        android:topLeftRadius="4dp" />

</shape>

您只需在 TextView 上设置 elevation 属性即可获得阴影(或者如果您使用的是 [=18 的旧版本,则将其包装在 CardView 中并设置 elevation tehre =])

您可以像下面提供的那样制作一个 XML 可绘制文件,然后将 android:background="@drawable/my_bg.xml" 放入您的文本视图中。

示例:my_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#EF4836"/>

    <stroke android:width="0dp"
        android:color="@android:color/transparent"
        />

    <padding android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp"
        />

    <corners android:bottomRightRadius="4dp" android:bottomLeftRadius="0dp"
        android:topLeftRadius="4dp" android:topRightRadius="0dp"/>
</shape>