Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...