Development/Android

[Android] View Tag 활용해서 접근하기

SeungYong.Lee 2025. 2. 4. 16:20
반응형
<View
    android:id="@+id/overDueTodoLine"
    android:layout_width="match_parent"
    android:layout_height="@dimen/line_size"
    android:layout_marginBottom="20dp"
    android:background="#DAE4E4E2"
    android:tag="4" />

- view는 id 외에 tag로도 접근 가능합니다.

val targetView = (this as ViewGroup).findViewWithTag<View>(number.toString())
targetView?.visibility = View.GONE

 

- XML이 아닌 코드에서 수정

targetView.tag = "001"
반응형