动态地改变资源文件的文件名中使用? [英] Dynamically change the name of the resource file to be used?

查看:129
本文介绍了动态地改变资源文件的文件名中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可以做到这样的:

if (colorScheme == 1)
    button.setBackgroundResource(R.drawable.button + "_1")

为了使用R.drawable.button_1作为资源此按钮在颜色方案1中,如果有一个名为button_1.png,button_2.png,button_3.png在可拉伸夹中的文件。
(动态地使用不同的资源文件的基础上正在使用的配色方案相同的用户界面元素?)

in order to use R.drawable.button_1 as the resource for this button in color scheme 1, if there are files named button_1.png, button_2.png, button_3.png in drawable folder. (dynamically use different resource file for the same UI element based on the color scheme being used?)

谢谢,

推荐答案

我做了使用则getIdentifier()的东西simular:

I've done something simular using getIdentifier():

int resId = context.getResources().getIdentifier("button_1","drawable",context.getPackageName());
button.setBackgroundResource(resId);

这篇关于动态地改变资源文件的文件名中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆