안드로이드 xml 디자인 변경 코드

hyihyi·2024년 1월 16일
0

TIL

목록 보기
35/69
post-thumbnail

📖 글자 밑에 밑줄 넣기

📝 string.xml + xml 수정

  1. string.xml에 아래의 코드를 추가한다.
<string name="underlined_text"><u>매너온도</u></string>
  1. xml에 아래와 같이 사용한다.
android:text="@string/underlined_text"

📖 이미지 테두리 둥글게 하기

📝 xml + 코드 수정

  1. res/drawable 폴더에 rounded_corners.xml 추가
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp" />
<solid android:color="@android:color/transparent" />
</shape>
  1. xml의 background에 rounded_corners.xml 적용
android:background="@drawable/rounded_corners"
  1. xml에 아래의 코드 적용
android:clipToOutline="true"
  1. Activity에 아래의 코드 적용
typeImage.clipToOutline = true

📖 textView 배경색 동적 변경할 때

📝 코드를 수정

  1. 아래는 xml에서 배경색을 바꿀 textView이다.
<TextView
            android:id="@+id/tv_DetailMBTI"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginEnd="10dp"
            android:background="@drawable/rounded_shape_10"
            android:backgroundTint="#6ECA59"
            android:gravity="center"
            android:text="ENTP"
            android:textSize="18sp"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="@+id/tv_Detailname"
            app:layout_constraintEnd_toStartOf="@+id/tv_Detailname"
            app:layout_constraintTop_toTopOf="@+id/tv_Detailname" />
  1. Activity에서 아래의 코드로 배경색을 바꿔준다.
binding.tvDetailMBTI.background.setTint(
    ContextCompat.getColor(
        requireContext(),
        MbtiManager.getCompatibilityColor(data.mbti)
    )
)

📖 최대 글자 길이 / 말줄임표

android:maxLines="1"
android:ellipsize="end"

📖 스크롤뷰 스크롤바 없애기

android:scrollbars="none"

오버스크롤 효과 없애고 싶을 때

android:overScrollMode="never":

📖 리사이클러뷰 미리보기

이 속성은 실제 앱에서는 아무런 영향을 주지 않고 오직 개발 환경에서 도움을 주는 것
아래의 코드를 추가하면 됨

tools:listitem="@layout/home_recycler_view_item"

만약 가로로 스크롤하고 싶을 때는 아래의 코드를 추가하면 됨

tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerHorizon"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"                         
    tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
	android:orientation="horizontal"
    tools:orientation="horizontal" />
profile
자유롭게 쓴 나의 자유로운 Development voyage⛵

0개의 댓글