android - 在Android中使用Kotlin时,使用camelCase在xml中标识ID

标签 android kotlin naming-conventions

我已经在Android上工作了几年了,并且在整个过程中,我一直使用下划线在xml中命名ID,例如blocked_numbers_title :

<TextView
        android:id="@+id/blocked_numbers_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Blocked Numbers"
        android:gravity="center"
        android:textSize="40sp"
        android:textColor="@color/colorTextPrimary"
        android:textStyle="bold"
        tools:ignore="MissingConstraints" />

由于在kotlin中我们可以像访问变量一样直接访问这些id,因此它们在下划线时看起来不太好,因为它们没有遵循camelCase。遵循camelCase在XML中命名ID以及blockedNumbersTitle 这样的好习惯,还是有更好的做法?

最佳答案

您可以使用CamelCase或任何其他格式的ID命名约定,只要您愿意,因为它是字符串变量。

请参阅文档以获取更多信息:

android kotlin official doc

关于android - 在Android中使用Kotlin时,使用camelCase在xml中标识ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59607844/

相关文章:

android - 如何将一个 ListView 放在另一个 ListView 中......?

android - 如何强制 manifest.json 在现有 Android 设备上刷新

android - 使用 rxbinding 时我应该取消订阅吗?

kotlin - 如何在 Kotlin 的一行中声明 startActivityforResult()?

android - 更改安卓 :digits programmatically

java - 相对布局中的 ViewPager 消耗完整高度(选项卡)

java - 在 java6 kotlin 项目和 java8 kotlin 项目之间共享 kotlin 源文件

python - 如何处理在 javascript 中生成并在 python DRF 中使用的请求主体 JSON 字段的命名约定差异?

add/set 方法的 Swift 命名约定

objective-c - 为什么谷歌建议在 Objective-C 中命名 iVars 时使用尾部下划线?