Monday, August 1, 2016

Custom Seekbar with Crystal Range Seekbar



compile 'com.crystal:crystalrangeseekbar:1.0.0'
 
activity_main
 
<?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:layout_width="match_parent" 
 android:layout_height="match_parent">

    <Button 
 android:id="@+id/btnNext" 
 android:text="NEXT" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" />

    <LinearLayout 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:layout_marginEnd="10dp" 
 android:layout_marginStart="10dp" 
 android:clipChildren="false" 
 android:orientation="vertical" 
 android:paddingBottom="20dp">

        <!-- seekbar option 1 --> 
 <RelativeLayout 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 android:clipChildren="false">

            <com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar 
 android:id="@+id/rangeSeekbar1" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" />
        </RelativeLayout>

        <!-- seekbar option 2 --> 
 <RelativeLayout 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="30dp" 
 android:clipChildren="false">

            <com.crystal.crystalrangeseekbar.widgets.BubbleThumbSeekbar 
 android:id="@+id/rangeSeekbar2" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 app:bar_color="#C69E89" 
 app:bar_highlight_color="#A54B17" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:left_thumb_color="#775E4F" 
 app:left_thumb_color_pressed="#4C2D1A" 
 app:max_value="150" 
 app:min_value="50" />

        </RelativeLayout>

        <!-- seekbar option 3 --> 
 <RelativeLayout 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="30dp" 
 android:clipChildren="false">

            <com.crystal.crystalrangeseekbar.widgets.BubbleThumbSeekbar 
 android:id="@+id/rangeSeekbar3" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 app:bar_color="#F7BB88"                 
app:bar_highlight_color="#E07416" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:left_thumb_image="@drawable/thumb" 
 app:left_thumb_image_pressed="@drawable/thumb_pressed" 
 app:max_value="100" 
 app:min_value="0" 
 app:steps="5" />
        </RelativeLayout>

    </LinearLayout>

</LinearLayout>
layout2
<?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" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical">


    <com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" />

    <com.crystal.crystalrangeseekbar.widgets.BubbleThumbRangeSeekbar 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 app:bar_color="#C69E89" 
 app:bar_highlight_color="#A54B17" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:left_thumb_color="#775E4F" 
 app:left_thumb_color_pressed="#4C2D1A" 
 app:max_value="150" 
 app:min_value="50" 
 app:right_thumb_color="#775E4F" 
 app:right_thumb_color_pressed="#4C2D1A" />

    <com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 app:bar_color="#8990C4" 
 app:bar_highlight_color="#2434AD" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:gap="20" 
 app:left_thumb_color="#1A246D" 
 app:left_thumb_color_pressed="#030B47" 
 app:max_value="100" 
 app:min_value="50" 
 app:right_thumb_color="#1A246D" 
 app:right_thumb_color_pressed="#030B47" /> 
 
 
 <com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 app:bar_color="#EE88F7" 
 app:bar_highlight_color="#D810EA" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:fix_gap="30"         
app:left_thumb_color="#8D0D99" 
 app:left_thumb_color_pressed="#56005E" 
 app:max_value="100" 
 app:min_value="0" 
 app:right_thumb_color="#8D0D99" 
 app:right_thumb_color_pressed="#56005E" />

    <com.crystal.crystalrangeseekbar.widgets.BubbleThumbRangeSeekbar 
 android:id="@+id/rangeSeekbar5" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 app:bar_color="#F7BB88"         
app:bar_highlight_color="#E07416" 
 app:corner_radius="10" 
 app:data_type="_integer" 
 app:left_thumb_image="@drawable/thumb" 
 app:left_thumb_image_pressed="@drawable/thumb_pressed" 
 app:max_value="100" 
 app:min_value="0" 
 app:right_thumb_image="@drawable/thumb" 
 app:right_thumb_image_pressed="@drawable/thumb_pressed" 
 app:steps="5" />

</LinearLayout>
 
public class Activiy2 extends AppCompatActivity {
    @Override 
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout2);
    }
}
 
public class MainActivity extends AppCompatActivity {
    Button btnNext;

    @Override 
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        btnNext = (Button) findViewById(R.id.btnNext);
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override 
 public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, Activiy2.class));
            }
        });
    }


}
 

2 comments:

  1. How can i set bar height and thump radius?

    ReplyDelete
  2. Is there any option to reset the range bar to initial state?

    ReplyDelete