android - 将 css 渐变转换为 android 渐变 (xml)

标签 android css gradient

我想将 css 渐变转换为 android xml 渐变(形状)文件

例如

background-image: linear-gradient(to right, #ff8177 0%, #ff867a 0%, #ff8c7f 21%, #f99185 52%, #cf556c 78%, #b12a5b 100%);

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="0"
        android:endColor="#b12a5b"
        android:startColor="#ff867a"
        android:type="linear" />
</shape>

我对css了解不多。我只知道 android 并且颜色只有三个参数 android:endColor, android:startColor, android:centerColor 我如何定义这个 %以及CSS中呈现的各种颜色

是否有任何在线工具可以让我通过提供 css 输入来生成 xml 文件。

最佳答案

我建议查看这个相关问题:Using a gradientDrawable with more than three colors set

使用 LinearGradient对象,您可以使用多种颜色和百分比停止定义渐变。

例如(借用我链接的问题):

LinearGradient linearGradient = new LinearGradient(0, 0, width, height,
        new int[] { 
            0xFF1e5799, 
            0xFF207cca, 
            0xFF2989d8, 
            0xFF207cca }, //substitute the correct colors for these
        new float[] {
            0, 0.40f, 0.60f, 1 },
        Shader.TileMode.REPEAT);

我链接的问题和 official documentation包含有关如何使用它的更多详细信息。

关于android - 将 css 渐变转换为 android 渐变 (xml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005189/

相关文章:

javascript - 使用 javascript 为门票添加 Shiny 渐变

android - adb 不被识别为内部或外部命令、可运行程序或批处理文件

java - 如何用java android jdk播放外部视频?

android - Android设备上的Gradlew?

javascript - 使用 document.activeElement 获取所选 li 中 img 的 id

algorithm - 多边形边梯度算法

android - React Native 迁移 - FaSTLane 构建仅在 CircleCI 上针对 iOS "Archive failed"失败

asp.net - 如何在保持文本区域的 "clickability"的同时通过超链接添加文本?

html - 使用 CSS 设置选择框的样式

Java Graphics2D - 绘制具有渐变不透明度的图像