国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android TextView 設置字體大小的方法

2020-04-11 10:50:11
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

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;@Overrideprotected 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("閆磊我愛你");edit.setTextColor(Color.BLUE);edit.setText("這是我的第一個TextView,嘿嘿", TextView.BufferType.EDITABLE);/*** 要設置文本的背景色,* 必須將文本設置成BufferType.SPANNABLE,BufferType.EDITABLE*/Spannable sp = (Spannable) edit.getText();//設置紅色背景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); //設置斜體sp.setSpan(new AbsoluteSizeSpan(80), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //設置字體大小edit.setText(sp);//edit.setHeight(60);//android.os.Process.killProcess(android.os.Process.myPid());}}@Overridepublic 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;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();//noinspection SimplifiableIfStatementif (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}}

以上代碼內容是小編給大家分享的Android TextView 設置字體大小的方法,希望對大家有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锡林浩特市| 高碑店市| 尖扎县| 昌平区| 大兴区| 聂荣县| 河南省| 岳阳县| 浦江县| 汉沽区| 布尔津县| 南乐县| 鄂州市| 普兰县| 河西区| 错那县| 辰溪县| 泸定县| 休宁县| 百色市| 信阳市| 新沂市| 华亭县| 金华市| 忻州市| 武平县| 洛南县| 阜阳市| 恩平市| 湘潭县| 汉中市| 乳源| 寿阳县| 南城县| 安陆市| 滦南县| 连山| 龙泉市| 海城市| 闻喜县| 威信县|