I'm developing a custom%%, where the colors of the screen elements will vary depending on their properties.
Example: If the type property of the Message object displayed is Activity
, then the following elements of the "Azul"
file 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 colors.xml
method:
@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 using the setBackgroundResource , but it did not work!
Any tips?