是否有关于如何命名资源的约定? [英] Are there conventions on how to name resources?

查看:36
本文介绍了是否有关于如何命名资源的约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>

我对我在这些布局中使用的任何尺寸、字符串、数字和颜色都采用相同的策略.但是,我确实尝试进行概括.例如,如果所有按钮都有一个共同的 textColor,我就不会在名称前加上布局.资源名称将是button_textColor".如果所有 textColors 都使用相同的资源,它将被命名为textColor".对于样式,通常也是如此.

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.

这篇关于是否有关于如何命名资源的约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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