Mega Code Archive
Set text to use bold and italic font style
package app.test;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.style.BackgroundColorSpan;
import android.text.style.StyleSpan;
import android.text.util.Linkify;
import android.widget.EditText;
import android.widget.TextView;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv =(TextView)this.findViewById(R.id.tv);
tv.setAutoLinkMask(Linkify.ALL);
tv.setText("asdf");
TextView tv3 =(TextView)this.findViewById(R.id.tv3);
tv3.setText("asdf",TextView.BufferType.SPANNABLE);
Spannable spn = (Spannable) tv3.getText();
spn.setSpan(new BackgroundColorSpan(Color.RED), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spn.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
EditText et =(EditText)this.findViewById(R.id.et);
et.setText("asdf");
Spannable spn2 = (Spannable) et.getText();
spn2.setSpan(new BackgroundColorSpan(Color.RED), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spn2.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
//main.xml
//strings.xml
Hello World, ActivityMenu
HelloMenu
button1
button2
I am a TextView
I am an EditText
AutoComplete:
MultiAutoComplete:
//styles.xml