1
I’m developing a Activity
customized, where the colors of the screen elements will vary according to their properties.
Example: If the property guy of the object Message exhibited is "Azul"
, then the following file elements colors.xml
will be used:
<item name="azulFundo" type="color">#979dfd</item>
<item name="azulTexto" type="color">#0011ff</item>
<item name="azulFundoFab" type="color">#343b93</item>
For this, I do the following in the method onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mensagem_view);
mView = RelativeLayout.class.cast(findViewById(R.id.activity_mensagem_view));
compartilharAction = FloatingActionButton.class.cast(findViewById(R.id.compartilharAction));
imagemTipo = ImageView.class.cast(findViewById(R.id.imagemTipo));
textMensagem = TextView.class.cast(findViewById(R.id.textMensagem ));
final String tipo = getIntent().getStringExtra(MESSAGE_TYPE);
if("Azul".equals(tipo)){
mView.setBackgroundColor(ContextCompat.getColor(getBaseContext(), R.color.azulFundo));
imageType.setImageDrawable(ContextCompat.getDrawable(getBaseContext(), R.drawable.azulImagem));
textMessage.setTextColor(ContextCompat.getColor( getBaseContext(), R.color.colorAguaTxt) );
compartilharAction.setBackgroundResource(R.color.azulTexto);
}else...
}
I tried through the setBackgroundResource, but it didn’t work!
Any hint?
Perfect, thank you very much!
– Thiago Luiz Domacoski