My seekbar class extends SeekBar and bar was looking "good", but when I added theme to activity where the bar is (AppCompat theme), bar still works as usual , but problem is with the look of it. I have bar similar to this one: https://images.zoftino.com/development/android-dev/ui/android-seekbar-materil-style-custom-color.png

Problem is that the line of progress isn't connecting to the progress thumb, it is interrupted on the left and right of the progress thumb. I'll try with some drawing...this is how it should look (and did look before): _________.________

This is how it looks now (after theme is added): ________ . _______

Line is not connecting with the thumb. I saw that when I press the thumb it animates, drawing white circle around the thumb, and that white circle fills this empty space around the progress thumb, so my guess is that the line is interrupted because of that.

Can someone confirm that this is reason, and, in any way, provide some solution to this if possible?

Theme:

<activity
        android:name=".activity.MainActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:launchMode="singleTask"
        android:screenOrientation="sensorLandscape"
        android:theme="@style/Theme.MyCompatTheme"/>

Style:

<style name="Theme.MyCompatTheme" parent="@style/Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Seekbar in layout:

<co.***.***.***.ProgressIndicator
                android:id="@+id/pl_current_programme_progress"
                style="@android:style/Widget.Holo.SeekBar"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_weight="1"
                android:maxHeight="6dp"
                android:minHeight="6dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:thumb="@drawable/progress_thumb"/>

Progress_thumb.xml drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <solid android:color="#00ffffff" />
        <size android:width="35dp" android:height="35dp" />
    </shape>
</item>
<item android:top="10dp" android:left="10dp" android:right="10dp" android:bottom="10dp">
    <shape android:shape="oval">

        <solid android:color="@color/progress_thumb_color" />

        <size android:width="15dp" android:height="15dp" />
    </shape>
</item>
</layer-list>

ProgressIndicator.class:

@SuppressLint("AppCompatCustomView")
public class ProgressIndicator extends SeekBar {

LayerDrawable progressBackgroundDrw;
Drawable backgroundDrawable;
Drawable progressDrawable;
Drawable secondaryProgressDrawable;
LayerDrawable progressThumb;
private boolean appliedBrandingForProgressRemainingTime;

public ProgressIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public ProgressIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

private void init() {
    setMax(0);
    setMax(100);

    progressBackgroundDrw = (LayerDrawable) getProgressDrawable();
    backgroundDrawable = progressBackgroundDrw.findDrawableByLayerId(android.R.id.background);
    progressDrawable = progressBackgroundDrw.findDrawableByLayerId(android.R.id.progress);
    secondaryProgressDrawable = progressBackgroundDrw.findDrawableByLayerId(android.R.id.secondaryProgress);
    progressThumb = (LayerDrawable) getResources().getDrawable(R.drawable.progress_thumb);



    if (AppData.appBranding != null) {
        int[] colors = new int[]{
                AppData.appBranding.getCatchupProgressColor(),
                AppData.appBranding.getCatchupProgressColor(),
                AppData.appBranding.getCatchupProgressColor(),
                AppData.appBranding.getCatchupProgressColor()
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setThumbTintList(new ColorStateList(AppData.appBranding.getAndroidStates(), colors));
        }
    }

    refreshDrawableState();
}

public void setPercent(final float percent) {
    post(new Runnable() {
        @Override
        public void run() {
            Log.d("progressUpdate", "current: " + getProgress() + ", set to: " + percent);
            ObjectAnimator animation = ObjectAnimator.ofInt(ProgressIndicator.this, "progress", (int) percent);
            animation.setDuration(200);
            animation.setInterpolator(new DecelerateInterpolator());
            animation.start();

            requestLayout();
            refreshDrawableState();
        }
    });
}

public void animatePercent(float percent, long duration) {
    setPercent(percent);
}

private boolean enabled = true;

public void enable() {
    enabled = true;
    setThumb(getResources().getDrawable(R.drawable.progress_thumb));

}

public void disable() {
    enabled = false;
    setThumb(getResources().getDrawable(R.drawable.transparent_thumb));

}

public boolean enabled() {
    return enabled;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    return !enabled || super.onTouchEvent(event);

}


public void applyBrandingForCatchupChannels() {
    PorterDuffColorFilter colorFilterForProgress = new PorterDuffColorFilter(AppData.appBranding.getCatchupProgressColor(), PorterDuff.Mode.SRC_IN);

    progressDrawable.setColorFilter(colorFilterForProgress);

    progressBackgroundDrw.setDrawableByLayerId(android.R.id.background, backgroundDrawable);
    progressBackgroundDrw.setDrawableByLayerId(android.R.id.progress, progressDrawable);
    progressBackgroundDrw.setDrawableByLayerId(android.R.id.secondaryProgress, secondaryProgressDrawable);

    refreshDrawableState();
}

public void applyBrandingForNonCatchupChannels() {
    PorterDuffColorFilter colorFilterForProgress = new PorterDuffColorFilter(AppData.appBranding.getNonCatchupProgressColor(), PorterDuff.Mode.SRC_IN);

    progressDrawable.setColorFilter(colorFilterForProgress);

    progressBackgroundDrw.setDrawableByLayerId(android.R.id.background, backgroundDrawable);
    progressBackgroundDrw.setDrawableByLayerId(android.R.id.progress, progressDrawable);
    progressBackgroundDrw.setDrawableByLayerId(android.R.id.secondaryProgress, secondaryProgressDrawable);

    refreshDrawableState();
}

public void applyBrandingForProgressRemainingTime() {
    if (!appliedBrandingForProgressRemainingTime) {
        PorterDuffColorFilter colorFilterForProgress = new PorterDuffColorFilter(AppData.appBranding.getProgressRemainingTimeColor(), PorterDuff.Mode.SRC_IN);

        backgroundDrawable.setColorFilter(colorFilterForProgress);

        progressBackgroundDrw.setDrawableByLayerId(android.R.id.background, backgroundDrawable);
        progressBackgroundDrw.setDrawableByLayerId(android.R.id.progress, progressDrawable);
        progressBackgroundDrw.setDrawableByLayerId(android.R.id.secondaryProgress, secondaryProgressDrawable);

        refreshDrawableState();
        appliedBrandingForProgressRemainingTime = true;
    }

}
}

1 Answers

0
Community On Best Solutions

Managed to fix the seekbar after changing theme to AppCompat. Just adding:

android:splitTrack="false"

in seekbar element inside layout makes the seekbar normal, with no empty space around thumb.