Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
How to change toolbar color according to the radio button selected after the second login using android kotlin

I need to change the toolbar color in the second login time according to the RadioButton selected in the first login time in android kotlin. I've used sharedPreferences to get the value of the radioButton selected in the first login.

To set the radio button value in sharedPreferences at the first login time, I've used the following code

fun setSharedPreferences() {
        val sharedPreferences = getSharedPreferences(myPreferences, Context.MODE_PRIVATE)
        val editor = sharedPreferences.edit()
        editor.putString("Selected Value",radioButtonValue)
        editor.apply()
    }

In the Second login time, I've used the below method to get the value from shared preferences that was already set at the first login time.

fun getSharedPreferences(): String {
         val prefs = getSharedPreferences(myPreferences, Context.MODE_PRIVATE)
         restoredValue= prefs.getString("text", devMode)
         return restoredValue
}

This the code that I've used to change the color of toolbar in the second login time

 val restoredText=getSharedPreferences()
 if(restoredText==="selectedRadioButtonValue")
 {
   toolbar.setBackgroundColor(Color.parseColor("#FF0000"));
 }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

first of all in your getSharedPreferences method you try to receive different key value than you set on the first login (you are saving first login state in Selected Value key and try to receive from different key which is text)

second for your answer try below code

val restoredText=getSharedPreferences()
 if(restoredText.equals("selectedRadioButtonValue"))
 {
   toolbar.setBackgroundDrawable(ColorDrawable(Color.parseColor("#YOUR_COLOR_CODE")))
 }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda