gpt4 book ai didi

Android 如何以编程方式访问 string.xml 文件中的字符串和 color.xml 中的颜色

转载 作者:行者123 更新时间:2023-11-29 16:00:06 24 4
gpt4 key购买 nike

我想知道如何以编程方式访问 xml 文件的字符串、颜色和维度。

有什么简单的方法可以访问它吗???

最佳答案

你会想要 Resources .

在 Activity 中,您可以使用getResources() 来检索该对象,然后只需使用

Resources res = getResources();
String string = res.getString( R.string.string_id );
int color = res.getColor( R.color.color_id )

等等

关于Android 如何以编程方式访问 string.xml 文件中的字符串和 color.xml 中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25277047/

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