Skip to content

Instantly share code, notes, and snippets.

@Felipe00
Last active August 29, 2015 14:25
Show Gist options
  • Save Felipe00/725f6c80a41be660c388 to your computer and use it in GitHub Desktop.
Save Felipe00/725f6c80a41be660c388 to your computer and use it in GitHub Desktop.
// 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