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));
效果圖:
當然:看了這篇博客,你還可以顯示下面這種效果,有需要的留言,很簡單,就是寫個倒計時類。順便用一下兩種顏色顯示的效果
效果圖:
謝謝你來過