2

I have created custom seekbar to make it work according to my need. There are two questions related to it.

Before it let me show you my code for seekbar

In android xml

<com.abc.projectname.customlayout.CustomHorizontalSeekBar
                    android:id="@+id/progressBar1"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="match_parent"
                    android:layout_height="80dp"
                    android:layout_centerVertical="true"
                    android:max="7650"
                    android:paddingLeft="30dp"  // Padding given to show thumbnail properly
                    android:paddingRight="30dp"
                    android:clickable="false"
                    android:paddingTop="20dp"
                    android:tag="drawable/seek_bar_layout_two"
                    android:thumb="@drawable/dial" />

CustomHorizontalSeekBar Is a class which I have created to get the tag from seekbar and set progress drawable value as whatever tag have supplied to support multiple theme

seek_bar_layout_two xml file

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+android:id/background"
        android:drawable="@drawable/deselect">
    </item>
    <item
        android:id="@+android:id/progress"
        android:top="20dp"
        android:bottom="20dp"
        android:drawable="@drawable/lt_grey_seek_bar">
    </item>
    <!-- android:drawable="@drawable/loadingbar"> -->

</layer-list>

Here deselect is and highlighted image which I want to show as background of seekbar permanently.

lt_grey_seek_bar xml

<?xml version="1.0" encoding="utf-8"?>

<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="horizontal"
    android:gravity="left" >

    <shape android:shape="rectangle" >
        <corners android:radius="5dp" />

        <stroke
            android:width="1dp"
            android:color="@color/lt_grey_border" />

        <gradient
            android:endColor="@color/lt_grey_end"
            android:startColor="@color/lt_grey_start" />
    </shape>

</clip>

Questions

1) Can I give same background image for custom seekbar for enable and disable state? If yes than how? It is a special need from my client and it is not necessary to show disable state.

What I have tried:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/seek_bar_layout_two xml" android:state_enabled="false"/>
    <item android:drawable="@drawable/seek_bar_layout_two xml" android:state_pressed="true"/>
    <item android:drawable="@drawable/seek_bar_layout_two xml" android:state_selected="true"/>
    <item android:drawable="@drawable/seek_bar_layout_two xml"/>
</selector>

But Still no success.

2) As you can see in my seekbar implementation I have given padding to show proper thumbnail. But when I click outside the drawn state of seekbar where this padding is available seekbar automatically turns into non highlighted form. How should I stop it?

Seekbar and its touch area by which it gets non highlight

Non highlight seekbar look

I have been trying lots of ways to make it work successfully but unable to do so. Can anyone provide me a solution.

This is what I have done in my custom seekbar class

Rect bounds = getProgressDrawable().getBounds();
setProgressDrawable(getResources().getDrawable(idByTag));
getProgressDrawable().setBounds(bounds);
  • you dont need any custom `SeekBar`, what you need instead is a custom progress `Drawable` (android:progressDrawable), set it via `setProgressDrawable(Drawable d)` – pskink Sep 12 '16 at 06:08
  • Yes I did it in the customseekbar class already but still no progress –  Sep 12 '16 at 06:17
  • `you dont need any custom SeekBar` – pskink Sep 12 '16 at 06:17
  • Could you please explain why I do not need any custom seekbar? Also check my updated question –  Sep 12 '16 at 06:19
  • so how does the source of `CustomHorizontalSeekBar` look like? – pskink Sep 12 '16 at 06:35
  • That I cannot show(Due to some legal issues) but simple concept is I have extracted Id from whatever tag I am passing in xml and than getting drawable from that id and setting into progressdrawable of seekbar which I have added into question –  Sep 12 '16 at 06:45
  • so as i said you only need a custom progress `Drawable` class, thats all – pskink Sep 12 '16 at 06:46
  • Could you please express your thoughts in form of words. I am unable to understand your perspective –  Sep 12 '16 at 06:55
  • just try something like this `class MyDrawable extends Drawable { ...` and do your custom drawing in `draw` method – pskink Sep 12 '16 at 07:01
  • Please check my xml files "seek_bar_layout_two xml " and "lt_grey_seek_bar xml" they are my custom progress drawable. again I am creating custom seekbar to support multiple theme in my own way. –  Sep 12 '16 at 07:05
  • did you try to create custom `Drawable` class? what problems do you have with it? – pskink Sep 12 '16 at 07:06
  • I do not know about custom drawable stuff could you please share you code or something to support your thoughts –  Sep 12 '16 at 07:12
  • something like [this](http://stackoverflow.com/a/21060826/2252830) – pskink Sep 12 '16 at 07:15
  • Do you have anything that we can achieve using XML? This is pro-grammatically and I do not want to achieve it like this according to current implementation. –  Sep 12 '16 at 08:33

0 Answers0