android TextView 设置字体大小
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("闫磊我爱你");
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());
}
} @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 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 SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
}
}
android TextView 设置字体大小的更多相关文章
- Android: TextView 及其子类通过代码和 XML 设置字体大小的存在差异的分析
原因: 在代码中通过 setTextSize(float size) 设置,使用的是 sp 为默认单位. 而 XML 中使用了 px,所以需要使用先把做好 sp 和 px 的转换工作. 最近在做 ap ...
- Android代码中设置字体大小,字体颜色,显示两种颜色.倒计时效果
Android代码中设置字体大小,字体颜色,显示两种颜色 在xml文件中字体大小用的像素 <TextView android:id="@+id/uppaid_time" an ...
- Android TextView设置个别字体样式
TextView进一步深化: Textview 能够对其文字进行格式化. 通过查询资料,了解到格式化文字的方式主要分为两大类: 第一类:HTML标签格式化文字 代码 ...
- Android Studio升级到0.8.1后怎样设置字体大小?
升级到0.8.1后.打开设置字体大小页面.你会发现无论是Default还是Darcula,都不同意你改变字体的大小.事实上这个是由于这两个模式是Android Studio自带模式,所以不同意你修改, ...
- android studio 更改背景和设置字体大小
1,设置字体大小 2,设置背景主题
- android TextView 设置部分文字背景色和文字颜色
通过SpannableStringBuilder来实现,它就像html里边的元素改变指定文字的文字颜色或背景色 public class MainActivity extends Activity { ...
- android TextView 设置部分文字背景色 和 文字颜色
通过SpannableStringBuilder来实现,它就像html里边的元素改变指定文字的文字颜色或背景色 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- 【转】CSS3的REM设置字体大小
rem 长度单位 在Web中使用什么单位来定义页面的字体大小,至今天为止都还在激烈的争论着,有人说PX做为单位好,有人说EM优点多,还有人在说百分比方便,以至于出现了CSS Font-Size: ...
- CSS3的REM设置字体大小
在Web中使用什么单位来定义页面的字体大小,至今天为止都还在激烈的争论着,有人说PX做为单位好,有人说EM优点多,还有人在说百分比方便,以至于出现了CSS Font-Size: em vs. px v ...
随机推荐
- 使用像AdminLTE的前端框架,树形导航菜单实现方式都有哪些?
之前用easyui等富前端框架开发的时候都是使用封装好的县城的插件,现在使用最新的类似AdminLTE似的前段框架实现树形菜单都用什么方式? 后台拼接html然后前端用JS append方法添加还是直 ...
- HDU 3639 SCC Hawk-and-Chicken
求SCC缩点,统计出每个SCC中的点的个数. 然后统计能到达u的最多的点的个数,可以反向建图,再dfs一遍统计出来. 最后说一下,有必要开一个标记数组,因为测试数据中有重边,结果无限WA. #incl ...
- loj2013 「SCOI2016」幸运数字
点分治+线性基 (为了这六个字窝调了一下午一晚上QAQ #include <iostream> #include <cstring> #include <cstdio&g ...
- 大数据学习——scala的wordCount小例子
val lines=List("hello tom hello jerry","hello tom hello kitty hello china") //方法 ...
- Jmeter Cluster
Jmeter 是开源软件,100%纯java应用程序,专门为负载测试和性能测试. Jmeter的特性包括: 1.负载测试和性能测试许多不同的服务器/协议类型: Web - HTTP, HTTPS SO ...
- API生命周期第二阶段——设计:如何设计API(基于swagger进行说明)
题外话 在新的项目中,推行了swagger用于对API的设计.以期待解决我们上篇博客中说到了一些现象,提升工作效率.那么,结合到当时和全项目组成员做培训,以及后续的给主要应用者做培训,以及当初自己接触 ...
- 实用jstl实现未登录时不能绕过登录界面的效果
package com.filter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; ...
- python多进程(multiprocessing)
最近有个小课题,需要用到双进程,翻了些资料,还算圆满完成任务.记录一下~ 1.简单地双进程启动 同时的调用print1()和print2()两个打印函数,代码如下: #/usr/bin/python ...
- CSS3的writing-mode属性
writing-mode这个CSS属性以前是IE的独有属性,IE5.5浏览器就已经支持了.在很长一段时间里,FireFox, Chrome这些现代浏览器都不支持writing-mode,各大现代浏览器 ...
- ACM程序设计选修课——1041: XX's easy problem(神烦的多次字符串重定向处理)
1041: XX's easy problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 41 Solved: 7 [Submit][Statu ...