gpt4 book ai didi

android - 如何使用资源值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:07 25 4
gpt4 key购买 nike

我需要在 build.gradle 中计算整数值,然后在我的 Java 代码中使用它。我尝试:

build.gradle:

android {
defaultConfig {
resValue "int", "MY_VAR_NAME", "123"
}
}

值目录中的 preprocess.xml:

<integer name="my_int_value">MY_VAR_NAME</integer>

我收到错误消息 Cannot resolve symbol MY_VAR_NAME

如何使用?有说明书吗?

最佳答案

对于整数你必须使用 Like

resValue "整数", "MY_VALUE", "123"

或者

gradle.properties 文件中定义您的值,就像这样!

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Xmx1536m
# Your Values
MY_VALUE="123"
MY_VALUE1="124"
MY_VALUE2="125"

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
#http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

从您的应用build.gradle 文件访问
resValue "integer", "my_value", (project.findProperty("MY_VALUE") ?: "0")
resValue "integer", "my_value1", (project.findProperty("MY_VALUE1") ?: "0")
resValue "integer", "my_value2", (project.findProperty("MY_VALUE2") ?: "0")

关于android - 如何使用资源值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28108443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com