Android遇到setTextColor无效的解决办法
2016-10-13 18:37
477 查看
设置颜色无效有两种场景:
一:当颜色值写在color.xml文件中:
mTv.setTextColor( mContext.getResources().getColor(R.color.text_color));
(注意color.xml文件中的 颜色值是以#号开头的rgb值,可以无透明值)
二:当颜色值在代码中:
这种情况颜色值是以0xff3b9bff的形式存在(注意Android的要以8位存在才能生效,ios是6位),代码如下:
mTv.setTextColor(0xff3b9bff);
重点来了,遇到兼容问题怎么办?
解决办法如下:
int titleTvColor = 0x99000000;
try {
titleTvColor = Integer.parseInt(item.color.replace("0x", ""), 16) + 0xff000000;
} catch (NumberFormatException e) {
e.printStackTrace();
}
mTv.setTextColor(titleTvColor);
屈服于ios,只能自己补位了。
一:当颜色值写在color.xml文件中:
mTv.setTextColor( mContext.getResources().getColor(R.color.text_color));
(注意color.xml文件中的 颜色值是以#号开头的rgb值,可以无透明值)
二:当颜色值在代码中:
这种情况颜色值是以0xff3b9bff的形式存在(注意Android的要以8位存在才能生效,ios是6位),代码如下:
mTv.setTextColor(0xff3b9bff);
重点来了,遇到兼容问题怎么办?
解决办法如下:
int titleTvColor = 0x99000000;
try {
titleTvColor = Integer.parseInt(item.color.replace("0x", ""), 16) + 0xff000000;
} catch (NumberFormatException e) {
e.printStackTrace();
}
mTv.setTextColor(titleTvColor);
屈服于ios,只能自己补位了。
相关文章推荐
- Android_setTextColor无效解决办法
- Android开发——ClipboardManager.setText()过期解决办法
- AndroidStudio——TextView文字左右滚动(跑马灯效果)无效解决办法
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)
- android setTextColor()无效问题
- android setTextColor()的参数设置不起作用的解决方法
- android checkBox setTextColor无效
- Android使用TextView,设置onClick属性无效解决办法
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)
- android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)
- android button setMinHeight setMinWidth 无效解决办法
- Android使用TextView,设置onClick属性无效解决办法
- Android SwipeRefreshLayout.setRefreshing(false)无效的解决办法
- Android setTextColor无效_安卓setTextColor()的参数设置方式
- android的scrollview视图内部的子视图中android:layout_height="fill_parent"无效的解决办法
- Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法