gpt4 book ai didi

android - 我可以在 Android 中使用不同颜色的 xml 文件吗?

转载 作者:搜寻专家 更新时间:2023-11-01 08:53:28 24 4
gpt4 key购买 nike

我的 Android 应用程序中有一个带有颜色的 xml 文件。我可以在代码中选择其中之一吗?

类似于:

(if value == 0) {
// I choose the file 'a'
} else {
// I choose the file 'b'
}

这可能吗??

提前致谢。

最佳答案

你可以这样做:

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v;
if(value == 0){
v = inflater.inflate(R.layout.file_yellow, null);
}else{
v = inflater.inflate(R.layout.file_green, null);
}
// do stuff with view

关于android - 我可以在 Android 中使用不同颜色的 xml 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21017483/

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