是否有关于如何命名资源约定?资源

2023-09-12 04:04:22 作者:过往成河。

有没有约定如何命名在Android的资源呢?例如,按钮,textViews,菜单等。

Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc.

推荐答案

我不知道是否有任何官方的建议。

I don't know whether there are any official recommendations.

有关在我的布局与小工具和容器的id,我用的约定:

For ids in my layouts with widgets and containers, I use the convention:

<layout>_<widget/container>_<name>

我做同样的策略,任何梦诗,字符串,数字和颜色我在这些布局中使用。不过,我试着归纳。例如,如果所有的按钮都有一个共同的文字颜色,我不会preFIX与布局的名称。资源名称将是button_textColor。如果所有textColors都使用相同的它将被命名为'文字颜色的资源。对于样式,这是通常情况下也是如此。

I do the same strategy for any dimens, strings, numbers, and colors I use in those layouts. However, I do try generalizing. e.g if all buttons have a common textColor, I won't prefix the name with the layout. The resource name would be 'button_textColor'. If all textColors are using the same the resource it will be named 'textColor'. For Styles, this is usually the case as well.

有关菜单中的资源使用:

For menu resources i use:

menu_<activity>_<name>

动画只是不同的,你不能使用大写字母。同去的绘制XML资源,我相信。

Animations are only different as you cannot use uppercase letters. Same goes for drawable xml resources, i believe.