Myk*_*eka 13 resources android text shape drawable
我可以在可绘制资源中创建文本形状吗?我在谷歌搜索但没有发现任何东西......这是我的可绘制文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="3dp" android:color="#QQffQQ"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item android:right="59dp" android:left="59dp">
<shape android:shape="rectangle">
<solid android:color="£22££20"/>
</shape>
</item>
<item android:top="59dp" android:bottom="59dp">
<shape android:shape="rectangle">
<solid android:color="£20££20"/>
</shape>
</item>
<item>
<!--text should be here-->
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
不,你不能这样做.但是,为什么不将Drawable
a 设置为背景TextView
,然后简单地设置文本TextView
,哪个将显示在你的其他图层上方Drawable
?
您可以使用 vector drawable 代替(例如通过从 svg 文件转换)。
然后使用矢量作为图层之一。
这使您可以创建一个没有任何 TextViews 的可绘制对象,因此您可以轻松地将其用作初始屏幕主题中的 windowBackground。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#C3DAE0"
android:endColor="#FFFFFF"
android:type="linear"/>
</shape>
</item>
<item
android:gravity="center"
android:drawable="@drawable/ic_splash_text"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
其中ic_splash_text - 是可随文本绘制的矢量。
如果您的目标是 API<21,请不要忘记添加向量支持。为此,您必须:
添加到您的模块 build.gradle(应用程序级):
android {
vectorDrawables.useSupportLibrary = true.
}
Run Code Online (Sandbox Code Playgroud)在活动的静态块中注册委托:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
20409 次 |
最近记录: |