Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda