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

我已经在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中以 blockedNumbersTitle 命名ID是一种好习惯吗?还是有更好的做法?

chenxiangxie0 回答:在Android中使用Kotlin时,使用camelCase在xml中标识ID

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

有关更多信息,请参阅文档:

android kotlin official doc

,

camelCase是一个不错的选择,因为它具有良好的可读性-您可以区分-和其紧凑性。关于可读性,有时很难识别变量名中的多个字母字符:textToDoAWorkAWork公园看上去有些疲惫,但总的来说,我认为这是最好的选择

本文链接:https://www.f2er.com/2814803.html

大家都在问