728x90

먼저 build.gradle 파일을 아래와 같이 수정합니다. minSdkVersion을 16으로 수정하고 dependencies에 아래처럼 코드를 추가해줍니다.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        ...
        minSdkVersion 16
        ...
    }

}

dependencies {
    ...
    implementation 'com.ebanx:swipe-button:0.8.3'
}

코드 추가 후 우측 상단의 Sync Now를 클릭해 줍니다.

 

다음으로 원하는 xml 파일에 가서 아래처럼 코드를 작성해줍니다. Layout은 RelativeLayout이어야 합니다.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...>

    <com.ebanx.swipebtn.SwipeButton
        android:id="@+id/swipe_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="34dp"
        android:layout_marginLeft="34dp"
        android:layout_marginEnd="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginBottom="82dp"
        app:button_background="@drawable/shape_button"
        app:button_bottom_padding="20dp"
        app:button_image_disabled="@drawable/alarm"
        app:button_image_enabled="@drawable/applogo"
        app:button_image_height="60dp"
        app:button_image_width="100dp"
        app:button_left_padding="20dp"
        app:button_right_padding="20dp"
        app:button_top_padding="20dp"
        app:has_activate_state="true"
        app:initial_state="disabled"
        app:inner_text="알람 시간이 되었습니다!"
        app:inner_text_background="@drawable/shape_rounded"
        app:inner_text_bottom_padding="18dp"
        app:inner_text_color="@android:color/white"
        app:inner_text_left_padding="80dp"
        app:inner_text_size="16sp"
        app:inner_text_top_padding="18dp" />
</RelativeLayout>

마지막으로 Java코드에서 Listener 사용하는 방법입니다. Listener 종류는 두가지입니다.

package my.homekeeper;

import com.ebanx.swipebtn.OnStateChangeListener;
import com.ebanx.swipebtn.SwipeButton;

public class AlarmActivity extends AppCompatActivity {
    
    SwipeButton swipeButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm);
        swipeButton = (SwipeButton) findViewById(R.id.swipe_btn);

        swipeButton.setOnStateChangeListener(new OnStateChangeListener() {
            @Override
            public void onStateChange(boolean active) {
                Toast.makeText(getApplicationContext(),"종료하였습니다.",Toast.LENGTH_LONG).show();
            }
        });
    }
}
	swipeButton.setOnActiveListener(new OnActiveListener() {
            @Override
            public void onActive() {
                Toast.makeText(getApplicationContext(),"종료하였습니다.",Toast.LENGTH_LONG).show();
            }
        });

자료출처 : https://github.com/ebanx/swipe-button/

728x90

+ Recent posts