字符串为Android的可绘制资源文件



嗨,我是kotlin/android编程的初学者,我正在尝试将字符串和图像添加到xml文件中

<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="234dp"
android:height="56dp"
android:viewportWidth="234"
android:viewportHeight="56"
>
<group>
<clip-path
android:pathData="M28 0H206C221.464 0 234 12.536 234 28C234 43.464 221.464 56 206 56H28C12.536 56 0 43.464 0 28C0 12.536 12.536 0 28 0Z"
/>
<path
android:pathData="M0 0V56H234V0"
android:fillColor="#34AB8F"
/>
<!--
Add string "Click on me"
-->
<!--
Add image: beautifulImage.png
-->
</group>
</vector>

你知道解决方案吗,有可能吗?

您共享的XML是矢量可绘制的,您不能在其中添加这样的字符串或图像,这是不可能的,如果您想向该可绘制文件或图像(矢量图像(添加字符串,您需要有该可绘制文件的svg文件,您可以在Adobe illustratorInkscape等软件中编辑该文件。

编辑后,您可以使用Resource manager将其导入到您的android工作室项目中

大多数Android开发人员使用JPG或SVG格式进行图像处理。JPG很容易在studio中添加(使用字符串(。

但是,不支持SVG格式的字符串。你必须把字符串转换成形状。您可以在Adobe Illustrator中通过在选择文本的同时选择展开选项(在"对象菜单"中(来执行此操作。

最新更新