我的 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/