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


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!