Skip to content

Not able to set stroke_width programmatically #22

Description

@jackthebeast

I'm extending the class so I don't have to set all the styles every time I use it, but setting stroke width from my sub class doesn't work. Here's my complete class:

class CustomCircleProgressBar(context: Context, attributes: AttributeSet?) : CircleProgressBar(
    context,
    attributes
) {

    constructor(context: Context) : this(context, null)

    init {
        setStyle(SOLID_LINE)
        setProgressStartColor(getContext().getColor(R.color.colorAccent))
        setProgressEndColor(getContext().getColor(R.color.colorAccent))
        setProgressBackgroundColor(getContext().getColor(R.color.colorPrimaryLight))
        setProgressTextColor(getContext().getColor(android.R.color.transparent))
        setProgressStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()))
    } 
}

the stroke remains 1dp thin.
Works correctly if set from xml: app:progress_stroke_width="5dp"

Other parameters are working correctly. It appears to me that the problem is due to initPaint() not being called after the new width is set.
Any way I can make it work?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions