有条件地加载其他位图

时间:2019-06-07 13:54:31

标签: android xml flutter

我有一个Flutter代码,可以生成2个不同的应用程序。我想为每个按钮指定一个不同的启动屏幕。

我尝试过的inspired by this answer

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <rule>
        <if>
            <conditions>
                <condition var="@string/app_name" operator="==">App1</condition>
            </conditions>
            <statements>
                <item>
                    <bitmap
                        android:gravity="center"
                        android:src="@drawable/app1_launch_image" />
                </item>
            </statements>
            <else>
                <statements>
                    <item>
                        <bitmap
                            android:gravity="center"
                            android:src="@drawable/app2_launch_image" />
                    </item>
                </statements>
            </else>
        </if>
    </rule>
</layer-list>

此代码产生相同的行为:

<?xml version="1.0" encoding="utf-8"?><!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <item android:drawable="@android:color/white" />

    <xsl:choose>
        <xsl:when test="{@string/app_name} == 'App1'">
            <item>
                <bitmap
                    android:gravity="center"
                    android:src="@drawable/app1_launch_image" />
            </item>
        </xsl:when>
        <xsl:otherwise>
            <item>
                <bitmap
                    android:gravity="center"
                    android:src="@drawable/app2_launch_image" />
            </item>
        </xsl:otherwise>
    </xsl:choose>
</layer-list>

它找不到我的资产,仅显示空白的启动屏幕。它似乎没有输入if语句。

我也尝试过的:

<item>
    <bitmap
        android:gravity="center"
        android:src="@{@string/app_name == @string/app1_name ? @drawable/app1_launch_image : @drawable/app2_launch_image}" />
</item>

但是它说'@{@string/app_name == @string/app1_name ? @drawable/app1_launch_image : @drawable/app2_launch_image}' is incompatible with attribute src (attr) reference|color.

0 个答案:

没有答案