简体   繁体   English

如何使用Android'flavor'strings.xml

[英]How to use Android 'flavor' strings.xml

I have an app which will have free and paid versions. 我有一个将提供免费和付费版本的应用程序。 I can successfully created 'flavors' in the build.gradle and created new folders under 'src'. 我可以在build.gradle中成功创建“风味”,并在“ src”下创建新文件夹。

I have added a strings.xml to each flavor. 我已经为每种口味添加了一个strings.xml。

src/flavor1/res/values/strings.xml src / flavor1 / res / values / strings.xml

src/flavor2/res/values/strings.xml src / flavor2 / res / values / strings.xml

It is one bool: 这是一个布尔:

<resources>
    <bool name="FullVersion">false</bool>
</resources>

One flavor is true, one is false. 一种味道是正确的,一种是错误的。 I don't have this same 'bool' in my 'strings.xml' under the main folder. 我的主文件夹下的'strings.xml'中没有相同的'bool'。

I am trying to reference this in a layout in the main folder to determine if something is enabled or disabled. 我正在尝试在主文件夹的布局中引用它,以确定是否启用了某些功能。

在此处输入图片说明

Looks like this is what has been confusing me. 看起来这就是让我感到困惑的东西。 You're right. 你是对的。 It does work however, my enabled shows an error and the preview won't render because of it. 它确实可以工作,但是启用后会显示错误,并且因此无法呈现预览。 It does work though 确实可以

Use android:enabled="@bool/FullVersion" . 使用android:enabled="@bool/FullVersion"

That being said, you might wish to move this resource to a bools.xml file, or at least out of strings.xml , to simplify your translation work. 话虽如此,您可能希望将此资源移到bools.xml文件中,或至少移出strings.xml ,以简化翻译工作。

I found the problem here. 我在这里发现了问题。 I needed to define more information in my 'flavors': 我需要在“风味”中定义更多信息:

minSdkVersion 15
targetSdkVersion 23
versionCode 1

Everything works now. 现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM