gpt4 book ai didi

java - 如何通过 Drawable 文件夹中的 XML 文件为 TextView 创建背景

转载 作者:行者123 更新时间:2023-12-01 13:39:26 25 4
gpt4 key购买 nike

以下是我想要实现的目标。

enter image description here

黑色粗方线是TextView尺寸的轮廓。圆角正方形周围的区域需要完全透明,以便背景可以从 TextView 所在的布局中显示出来。

我认为这是通过在 Drawable 文件夹中创建一个文件来实现的,该文件需要使用诸如 linessolid 等命令, corners 和类似的东西,但我不知道从那里去哪里。我很难找到任何完整而彻底的教程来帮助解决这个问题。下面是我开始的地方,但无法进一步深入。

<shape 
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@android:color/transparent"/>
<stroke
android:width="2dp"
android:color="#000000"/>
<corners
android:radius="8dp" />
</shape>

但这与我上面的图片并不接近。我的问题是如何调整上面的代码以获得我想要的图片?

最佳答案

尝试这个形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:endColor="#000000" android:startColor="#000000" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>

然后你像这样设置你的文本字段:

<TextView 
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roundedView"
/>

关于java - 如何通过 Drawable 文件夹中的 XML 文件为 TextView 创建背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20954343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com