개발하는 두더지

[Android] Ripple Effect 란? 본문

Java,Android

[Android] Ripple Effect 란?

덜지 2018. 5. 8. 19:48

Ripple Effect

Ripple Effect 는 Android 5.0 (API level 21) 머터리얼 디자인에 소개되었습니다.

예를들어 버튼을 클릭했을 때 물결이 퍼지듯이 효과가 나오는 기능입니다.

5.0 미만에는 색상만 변경되고, 이상은 RippleDrawable까지 적용됩니다.


적용하는 방법에는 크게 2가지가 있습니다.



이미 정의되어있는 Style 사용

android:background="?android:attr/selectableItemBackground"


minSdkVersion 21 이상인 경우

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="android:colorControlHighlight">#FF00FF</item>
</style>

위와 같이 테마에서 직접 물결을 적용할 색을 지정 할 수 있습니다.  테마 스타일을 변경하게 되면 colorControlHighlight가 사용되는 모든 컨포넌트에 일괄 적용 할 수 있습니다. 



Custom Style 사용

res/drawable 폴더에 custom_ripple_effect.xml 파일을 만들고 아래와 같이 적용합니다.

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF00FF"> <!-- Ripple Effect 색상 -->

<!-- 배경색 -->
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="#AA0000"/>
</shape>
</item>

</ripple>

<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="@drawable/custom_ripple_effect"
    ...
/>




참고


공식문서


선택 가능한 항목의 Foreground에 터치 피드백 쉽게 적용하기(Selector / Ripple Drawable) - 커니의 안드로이드


ripple effect 적용 예시

Comments