Mehmet Ethem SULAN :: Android :: Android TextView bold italic underline Sample

Android ile bir TextView değerlerini bold, underline ve italic yazmaya çalıştım.
Texview içine aşağıdaki özellikleri ekledim

android:textStyle="italic|bold|normal" 

Underline için de SpannableString isminde bir sınıf var.

main.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_height="wrap_content" 
    android:id="@+id/textView1_underline" 
    android:text="TextView" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textStyle="italic|bold|normal"
    android:layout_width="wrap_content">
    </TextView>
</LinearLayout>

UnderlineTextActivity.java

package com.underline;

import android.app.Activity;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.ViewDebug.FlagToString;
import android.widget.TextView;

public class UnderlineTextActivity extends Activity {
    private TextView textView_underline;
    private SpannableString spString;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
//Yazilan textin altini çiziyorum.
        spString=new SpannableString("http://esulan.blogspot.com");
        spString.setSpan(new UnderlineSpan(), 0, spString.length(), 0);
        textView_underline=(TextView) findViewById(R.id.textView1_underline);
       
        textView_underline.setText(spString);
        
    }
}

Download UnderlineText.tar.gz

Write a Comment

Let me know what you think?