Android TextView How to set the font size _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.