Last active
August 29, 2015 14:25
-
-
Save Felipe00/725f6c80a41be660c388 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cria essa variável antes de chamar o método | |
// Aqui você instancia um Handler, que é uma Atividade (Task) de segundo plano semelhante à AsynkTask. | |
Handler handler = new Handler(); | |
/** | |
* Chama esse método de onde vc quer que o layout mude. | |
* Ex: Dentro do onCreate. | |
*/ | |
public void metodoParaMudarBackground(Context context) { | |
// Executa uma thread. | |
handler.post(r); | |
} | |
// Thread pra mudar a cor. | |
final Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
// Aqui eu pego o ID do meu LinearLayout (obs.: pode ser qualquer layout) | |
LinearLayout novoLayout = findViewById(R.id.idDoLinearLayout); | |
//Aqui eu seto a Cor BRANCA no meu layout. | |
novoLayout.setBackgroundColor((new Color()).WHITE); | |
// Passados 2000 mili segundos (ou 2 segundos) ela executa a thread novamente. | |
handler.postDelayed(this, 2000); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment