我已经在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/