[Android] 안드로이드 스튜디오 FloatingActionButton tint 속성 적용이 안될 때

Choi Sang Rok·2022년 1월 8일
3

> 개발자로서의 첫 블로그 첫 게시글입니다. 미흡한 글이더라도 잘 봐주시면 감사하겠습니다.
오타 지적 감사합니다.

error)

FloatingActionButtontint 속성을 변경하려고 하던 도중, white 색상을 지정하여도 색상이 변하지 않았다.

분명히 tint 속성을 white로 했음에도 불구하고 색상이 변하지 않는다. 왜 그런것일까? 해결법은 간단했다.

해결 방법)

android:tint="@color/white"

android: -> app:으로 바꿔주면 된다.

app:tint="@color/white"



이유가 무엇인가?

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

xmlns는 xml의 네임스페이스를 의미한다.
"URL"리소스의 속성들을 android라는 접두어를 통해 접근할 수 있다는 의미이다.

http://daplus.net/android-%EC%99%9C%EC%9D%B4-%EC%A4%84-xmlns-android-http-schemas-android-com-apk-res-android%EA%B0%80-%EB%A0%88%EC%9D%B4%EC%95%84%EC%9B%83-xml-%ED%8C%8C%EC%9D%BC%EC%97%90/

xmlns:android : 안드로이드 기본 SDK에 포함된 속성을 사용한다.
xmlns:app : 프로젝트에서 사용하는 외부 라이브러리에 포함된 속성을 사용한다.
xmlns:tools : 안드로이드 스튜디오의 디자이너 도구 등에서 화면에 보여줄 때 사용된다.(앱이 실행될 때는 적용되지 않음)

com.google.android.material.floatingactionbutton.FloatingActionButton

안드로이드 디자이너에서 오른쪽 어트리뷰트에 있는 tint 속성에 값을 넣으면 android:tint에 설정이 적용되기 때문에 바뀌지 않는다.

플로팅액션버튼은 외부 라이브러리에서 참조하기 때문에, app:tint 속성을 사용함으로써 tint 속성이 적용되지 않는 것을 해결할 수 있다.

profile
android_developer

4개의 댓글

comment-user-thumbnail
2022년 1월 8일

화이팅해요~!

1개의 답글
comment-user-thumbnail
2022년 1월 8일

좋은 글 감사합니다 :)

1개의 답글