Android การเปลี่ยน Style ของ Font ที่แตกต่างกันใน TextView อันเดียวกัน
ตัวอย่างโค้ด
@Override
protected void onFinishInflate() {
super.onFinishInflate();
CharSequence charSequence = this.getText();
SpannableString spannableString = new SpannableString(charSequence);
spannableString.setSpan(new RelativeSizeSpan(2.0f), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
this.setText(spannableString);
}
จากโค้ดนี้เราได้ทำการ Override เมทอดที่ชื่อว่า onFinishInflate ใน TextView ขึ้นมาในกรณีที่ต้องการเปลี่ยน Font หลังจากที่มัน Inflate เสร็จแล้ว จากนั้นก็ทำการเปลี่ยนขนาดของมัน
ไม่มีความคิดเห็น:
แสดงความคิดเห็น