Android代码中设置字体大小,字体颜色,显示两种颜色汇总

Android代码中设置字体大小,字体颜色,显示两种颜色

在xml文件中字体大小用的像素

<TextView

           android:id="@+id/uppaid_time"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/title"
           android:layout_centerHorizontal="true"
           android:layout_marginTop="@dimen/dip_8"
           android:text="超过15分钟未支付,订单自动取消(还剩:xxx)"
           android:textColor="#888"
           android:textSize="@dimen/dip_12" />

<dimen name="dip_12">12dp</dimen>

如果在代码中想动态改变字体属性,于是直接用
大小:
uppaid_time.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.dip_18));
颜色:

  uppaid_time.setTextColor(Color.BLACK);  //方法一

  uppaid_time.setTextColor(Color.parseColor("#909090"));   //方法二
  uppaid_time.setTextColor(getResources().getColor(R.color.white))   //方法三

两种颜色显示:

      String content = "<font color=\"#2b92f2\">" +"0030 5462 3645 "+"</font>";
      uppaid_time.setText(Html.fromHtml("兑换码: " + content));

效果图:

当然:看了这篇博客,你还可以显示下面这种效果,有需要的留言,很简单,就是写个倒计时类。顺便用一下两种颜色显示的效果
效果图:

谢谢你来过

猜你喜欢

转载自blog.csdn.net/heishuai123/article/details/80253801