Android SetTextColor work without Build.VERSION.SDK_INT checking
Normal :
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M )
{
dynamicTextView.setTextColor(
m_ctx.getResources().getColor( R.color.black, null ) );
}
else
{
dynamicTextView.setTextColor(
m_ctx.getResources().getColor( R.color.black ) );
}
Another Way (Better) :
dynamicTextView.setTextColor(
Color.parseColor( m_ctx.getResources().getString(
R.color.black ) ) );
PS. R.color.black is a value in xml file, Color.parseColor can convert color string as #AARRGGBB or #RRGGBB.
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M )
{
dynamicTextView.setTextColor(
m_ctx.getResources().getColor( R.color.black, null ) );
}
else
{
dynamicTextView.setTextColor(
m_ctx.getResources().getColor( R.color.black ) );
}
Another Way (Better) :
dynamicTextView.setTextColor(
Color.parseColor( m_ctx.getResources().getString(
R.color.black ) ) );
PS. R.color.black is a value in xml file, Color.parseColor can convert color string as #AARRGGBB or #RRGGBB.
留言
張貼留言