Cómo establecer el color del texto en una vista de texto mediante programación [duplicar]
Esta pregunta ya tiene una respuesta aquí:
¿Cómo puedo establecer el Color del texto de una vista de texto en #bdbdbd
programáticamente?
199
4 answers
Uso..
Color.parseColor("#bdbdbd");
Como,
mTextView.setTextColor(Color.parseColor("#bdbdbd"));
O si ha definido código de color en el archivo color.xml
del recurso que
(De API >= 23)
mTextView.setTextColor(ContextCompat.getColor(context, R.color.<name_of_color>));
(Para API
mTextView.setTextColor(getResources().getColor(R.color.<name_of_color>));
497
Author: user370305,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-26 19:29:10
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-26 19:29:10
Grandes respuestas. Agregar uno que cargue el color desde un xml de recursos de Android pero que aún lo establezca mediante programación:
textView.setTextColor(getResources().getColor(R.color.some_color));
Tenga en cuenta que desde API 23, getResources().getColor()
está obsoleto. Use en su lugar:
textView.setTextColor(ContextCompat.getColor(context, R.color.some_color));
Donde el color requerido se define en un xml como:
<resources>
<color name="some_color">#bdbdbd</color>
</resources>
Actualización:
Este método fue obsoleto en el nivel de API 23. Usar getColor (int, Tema) en su lugar.
Compruebe esto .
208
Author: AlikElzin-kilaka,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:44
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:44
yourTextView.setTextColor(color);
O, en su caso: yourTextView.setTextColor(0xffbdbdbd);
33
Author: Jave,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-12 09:42:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-12 09:42:32
TextView tt;
int color = Integer.parseInt("bdbdbd", 16)+0xFF000000;
tt.setTextColor(color);
También
tt.setBackgroundColor(Integer.parseInt("d4d446", 16)+0xFF000000);
También
tt.setBackgroundColor(Color.parseColor("#d4d446"));
Véase:
18
Author: Marek Sebera,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:55:00
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:55:00