Nonsense not to say more, directly to everyone to paste the code, the specific code as follows:
Package com.example.yanlei.yl4;
Import Android.graphics.Color;
Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import android.text.Spannable;
Import Android.text.style.AbsoluteSizeSpan;
Import Android.text.style.BackgroundColorSpan;
Import Android.text.style.StyleSpan;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.TextView;
public class Mainactivity extends appcompatactivity {TextView edit;
Button Sendbu; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
Edit = (TextView) Findviewbyid (R.id.textview);
Sendbu = (Button) Findviewbyid (R.id.button);
Sendbu.setonclicklistener (New Buttonclicklistener ()); Private class Buttonclicklistener implements View.onclicklistener {public void OnClick (View v) {//system.exit (0); edit
. SetText ("Len Lei I Love You"); Edit.settextcolor (Color.Blue);
Edit.settext ("This is my first TextView, hehe", TextView.BufferType.EDITABLE);
/** * To set the background color of the text, * The text must be set to Buffertype.spannable,buffertype.editable/spannable SP = (spannable) edit.gettext ();
Set Red background Sp.setspan (new Backgroundcolorspan (color.red), 3, 8, spannable.span_exclusive_exclusive); Sp.setspan (New Stylespan (Android.graphics.Typeface.BOLD_ITALIC), 0, 7, spannable.span_exclusive_exclusive); Set Italic Sp.setspan (new Absolutesizespan, 0, 2, spannable.span_exclusive_exclusive);
Set Font size edit.settext (SP);
Edit.setheight (60);
Android.os.Process.killProcess (Android.os.Process.myPid ()); }} @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it
is present.
Getmenuinflater (). Inflate (R.menu.menu_main, menu);
return true; @Override public boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar would//automatically handle clicks on the Home/up button, so long//ASSpecify a parent activity in Androidmanifest.xml.
int id = item.getitemid (); Noinspection simplifiableifstatement if (id = = r.id.action_settings) {return true;} return super.onoptionsitemselecte
D (item); }
}
The above code content is small to share the Android TextView set font size method, I hope to help.