상세 컨텐츠

본문 제목

[안드로이드] 색상 선택 색상표 쉽게 만드는 방법

안드로이드

by aries574 2022. 2. 2. 11:30

본문


이번 시간에는 색상 선택을 할 수 있는 색상표를

쉽게 만드는 방법에 대하여 알아보겠습니다.


목차

1. 실행 화면

2. 라이브러리 등록

3. 메인 화면 구성 activity_main.xml

4. 메인 코드 구현 MainActivity.java


1. 실행 화면

 

2. 라이브러리 등록

build.gradle(Module:프로젝트명:app)

dependencies 괄호 안에 아래 코드를 넣어주시면 됩니다.

implementation "com.github.skydoves:colorpickerview:2.2.4"

참조 문서

https://github.com/skydoves/ColorPickerView

 

GitHub - skydoves/ColorPickerView: 🎨 Android colorpicker for getting colors from any images by tapping on the desired color.

🎨 Android colorpicker for getting colors from any images by tapping on the desired color. - GitHub - skydoves/ColorPickerView: 🎨 Android colorpicker for getting colors from any images by tapping on...

github.com

 

 

3. 메인 화면 구성 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- 선택한 색상값 -->
    <TextView
        android:id="@+id/color_text_view"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:gravity="center"
        android:textSize="20sp" />

    <!-- 선택한 색상 -->
    <View
        android:id="@+id/color_view"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp" />

    <!-- 색상표 -->
    <com.skydoves.colorpickerview.ColorPickerView
        android:id="@+id/colorPickerView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp" />



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:textSize="20sp"
        android:text="밝기 조절"/>

    <!-- 밝기 -->
    <com.skydoves.colorpickerview.sliders.BrightnessSlideBar
        android:id="@+id/brig_slideBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:borderColor_BrightnessSlider="@android:color/darker_gray"
        app:borderSize_BrightnessSlider="5"
        app:selector_BrightnessSlider="@drawable/wheel" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:textSize="20sp"
        android:text="투명도 조절"/>

    <!-- 투명도 -->
    <com.skydoves.colorpickerview.sliders.AlphaSlideBar
        android:id="@+id/alph_slideBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:borderColor_AlphaSlideBar="@android:color/darker_gray"
        app:borderSize_AlphaSlideBar="5"
        app:selector_AlphaSlideBar="@drawable/wheel" />

</LinearLayout>

아이콘 res -> drawable

wheel.png
0.00MB



4. 메인 코드 구현 MainActivity.java

public class MainActivity extends AppCompatActivity {

    TextView colorTextView;
    View colorView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        colorTextView = findViewById(R.id.color_text_view);

        colorView = findViewById(R.id.color_view);

        ColorPickerView colorPickerView = findViewById(R.id.colorPickerView);
        colorPickerView.setColorListener(new ColorEnvelopeListener() {
            @Override
            public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {

                colorTextView.setText(envelope.getHexCode());

                colorView.setBackgroundColor(envelope.getColor());
            }
        });

        //밝기 조절 슬라이더 
        BrightnessSlideBar brigSlideBar = findViewById(R.id.brig_slideBar);
        colorPickerView.attachBrightnessSlider(brigSlideBar);

        //투명도 조절 슬라이더
        AlphaSlideBar alphaSlideBar = findViewById(R.id.alph_slideBar);
        colorPickerView.attachAlphaSlider(alphaSlideBar);
    }//onCreate

} //MainActivity

2022.02.01 - [안드로이드] - [안드로이드] 애니메이션 시계(ClockAnimationView) 쉽게 만드는 방법

 

[안드로이드] 애니메이션시계(ClockAnimationView) 쉽게 만드는 방법

이번 시간에는 애니메이션 시계 쉽게 만드는 방법에 대하여 알아보겠습니다. 목차 1. 실행 화면 2. 라이브러리 등록 3. 메인 화면 구성 activity_main.xml 4. 메인 코드 구현 MainActivity.java 1. 실행..

aries574.tistory.com

2022.01.31 - [안드로이드] - [안드로이드] 토글 버튼(Toggle) 쉽게 꾸미는 방법

 

[안드로이드] 토글버튼(Toggle) 쉽게 꾸미는 방법

이번 시간에는 토글버튼 쉽게 꾸미는 방법에 대하여 알아보겠습니다. 토글버튼은 둘 중 하나를 선택하는 간단한 모양의 버튼입니다. 목차 1. 실행 화면 2. 라이브러리 등록 3. 메인 화면 구성 a

aries574.tistory.com

2022.01.30 - [안드로이드] - [안드로이드] 통화 코드 통화 상징 가져오는 드롭다운 메뉴(DropDown Menu) 쉽게 만드는 방법

 

[안드로이드] 통화코드 통화상징 가져오는 드롭다운메뉴(DropDown Menu) 쉽게 만드는 방법

이번 시간에는 통화코드 통화상징 가져오는 드롭다운메뉴 쉽게 만드는 방법에 대하여 알아보겠습니다. 목차 1. 실행 화면 2. 라이브러리 등록 3 메인 화면 구성 activity_main.xml 4. 메인 코드

aries574.tistory.com

 

반응형

관련글 더보기

댓글 영역