开发者

Resource referencing in android

开发者 https://www.devze.com 2023-03-09 08:47 出处:网络
I am newbie to Android and playing with some Hello World codes.I observed that android put every resource i.e. image,string etc in res folder and we 开发者_如何学JAVAaccess it like @drawable/icon i.e

I am newbie to Android and playing with some Hello World codes.I observed that android put every resource i.e. image,string etc in res folder and we 开发者_如何学JAVAaccess it like @drawable/icon i.e icon image in drawable folder or like R.layout.main which means main.xml inside layout folder.

But while accessing strings we use @string/string_name but we dont specify its parent folder name i.e.values.Why syntax differs for strings ?

It may sound silly but it makes to think and put this question.


All resources of the same type in android is in a flat hierarchy. You don't specify a directory name but instead the type of the resource.

Even if you split all strings between different files it will always be @string/string_name I'm afraid.

A good thing you can do to get some structure is to do something similar to this:

@string/error_network_io
@string/error_network_unknown_host
@string/message_save_successful
...
0

精彩评论

暂无评论...
验证码 换一张
取 消