Jignesh Ansodariya Jignesh Ansodariya - 4 months ago 127
Android Question

How to make slide to unlock button in android

Hi I want a button that should work as 'slide to unlock' button of IOS

in short I want a button that has no click effect but can slide left to right while drag and on drag completion it should considered click.

please suggest me any sample code if possible.

Thanks!

Answer

First of all I'd like to thank @matthias for his answer. I have used the following seek bar with some customization:

 <SeekBar
        android:id="@+id/myseek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:max="100"
        android:progressDrawable="@android:color/transparent"
        android:thumb="@drawable/ic_launcher" />

and in java code

sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

            if (seekBar.getProgress() > 95) {

            } else {

                seekBar.setThumb(getResources().getDrawable(R.drawable.ic_launcher));
            }

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {


        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            if(progress>95){
                seekBar.setThumb(getResources().getDrawable(R.drawable.load_img1));
            }

        }
    });
Comments