xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
ジャバ:
public class TextDemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ViewWithRedDot(this));
}
}
class ViewWithRedDot extends View {
public ViewWithRedDot(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Paint circlePaint = new Paint();
Typeface mType = Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC);
circlePaint.setTextSize(25);
circlePaint.setColor(Color.RED);
circlePaint.setTypeface(mType);
canvas.drawText("Default Typeface", 50, 100, circlePaint);
//
circlePaint.setFlags(Paint.UNDERLINE_TEXT_FLAG);
circlePaint.setColor(Color.YELLOW);
canvas.drawText("Underline Text Flag", 50, 120, circlePaint);
//
circlePaint.setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
circlePaint.setColor(Color.GREEN);
canvas.drawText("Strike Thru Text Flag", 50, 140, circlePaint);
//
circlePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(Color.WHITE);
canvas.drawText("Anti Alias Flag", 50, 160, circlePaint);
//
circlePaint.setFlags(Paint.DEV_KERN_TEXT_FLAG);
circlePaint.setColor(Color.WHITE);
canvas.drawText("Dev Kern Text Flag", 50, 180, circlePaint);
//
circlePaint.setFlags(Paint.FAKE_BOLD_TEXT_FLAG);
circlePaint.setColor(Color.CYAN);
canvas.drawText("Fake Bold Text Flag", 50, 200, circlePaint);
}
}