Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

android - Custom resource folder name (e.g. resdrawable-gamepad)

I'm adding gamepad support to my game. I need a lot of resources (strings, drawables) specific to gamepad. Specifying a different name for a gamepad resource is not very efficient, as I have to write a lot of code like this:

if (gamepadDetected) {
   image.setImageDrawable(getResources().getDrawable(R.drawable.controls_gamepad));
} else {
   image.setImageDrawable(getResources().getDrawable(R.drawable.controls_touch));
}

The easiest way would be to create a new directory, say resdrawable-gamepad and somehow instruct Android to use resources from this folder when my game detects gamepad. This way I could use the same names for resources (say resdrawablecontrols.jpg and resdrawable-gamepadcontrols.jpg). But I'm guessing this is not possible.

Is there any other easy way to add alternate resources to the existing project?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

custoum folders are not supported in the res folder but you can use the assets folder for you own folder structure.

see the Link: Difference between /res and /assets directories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...