acefalobi / android-stepper

A library for creating a wizard-like step-through user interface that uses navigation components and menus for displaying steps with advanced customization.
Apache License 2.0
325 stars 38 forks source link

How I can change the stepper color when it is completed #35

Closed shadab-saif closed 2 years ago

shadab-saif commented 2 years ago

I want to change the color of widget when the step is competed, How I can achieve it.

acefalobi commented 2 years ago

You can programmatically change the stepperView.widgetColor to the new color in the StepperNavListener.onCompleted() overrien method.

shadab-saif commented 2 years ago

You can programmatically change the stepperView,widgetColor to the new color in the StepperNavListener.onCompleted() overrien method.

lateinit var stepper: StepperNavigationView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_registration)

    val navHostFragment =
        supportFragmentManager.findFragmentById(R.id.frame_stepper) as NavHostFragment
    val navController = navHostFragment.navController

    val stepper = findViewById<StepperNavigationView>(R.id.stepper)
    stepper.setupWithNavController(navController)

}

override fun onCompleted() {
    stepper.widgetColor = R.color.purple_200
}

override fun onStepChanged(step: Int) {
    TODO("Not yet implemented")
}

here is my code but it is not working

acefalobi commented 2 years ago

stepperView.widgetColor takes in a ColorInt and not a ColorRes. You'll need to use context.getColor(R.color.purple_200) or ContextCompat.getColor(context, R.color.purple_200) instead

shadab-saif commented 2 years ago

stepperView.widgetColor takes in a ColorInt and not a ColorRes. You'll need to use context.getColor(R.color.purple_200) or ContextCompat.getColor(context, R.color.purple_200) instead

stepper.widgetColor = ContextCompat.getColor(applicationContext, R.color.purple_200) (not working)

acefalobi commented 2 years ago

Just to confirm, do you want to do this when it's completed or when it gets to the last step.

Because, if it is the latter, you need to put the widget color change in the onStepChanged() function.

e.g

override fun onStepChanged(step: Int) {
    if (step == noOfSteps) stepper.widgetColor = ContextCompat.getColor(applicationContext, R.color.purple_200)
}
shadab-saif commented 2 years ago

These both override function are not even call I have used toast message just to check these function are working or not, and I don't even see the toast.

acefalobi commented 2 years ago

Have you connected the listener to the stepperView with stepperView.stepperNavListener = this

shadab-saif commented 2 years ago

I have not connected the listener but now it is working when connected the listener, But it does not give me what I want, I want only completed widget step color change but it will change the complete stepper color.

acefalobi commented 2 years ago

Sorry @shadab-saif, unfortunately, the library doesn't include this functionality. But you can always fork the project and add this,