参考:http://guides.codepath.com/android/Working-with-the-TextView#using-custom-fonts
1. 限制行数android:singleLine="true"
android:lines="1"
2. 限制输入android:inputType="number"
只能输入数字并且只能输入01和5个长度
android:digits="01"android:maxLength="5"
3. 调整选中文本的颜色:android:textColorHighlight="#7cff88"
4. 调整低栏颜色,重写样式文件<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#d32f2f</item>
<item name="colorControlActivated">#ff5722</item>
<item name="colorControlHighlight">#f44336</item>
</style>
不知道为什么没有效果
参考:http://guides.codepath.com/android/Working-with-the-EditText#displaying-floating-label-feedback
TextView
手机一般自带三种标准字体Droid Sans, Droid Sans Mono and Droid Serif,使用android:typeface=""
属性可以使用normal选项默认就是sans
textStyle
android:textStyle="bold"
一般三种属性bold加粗,italic斜体
android:textStyle="bold|italic"
设置最大最小行数:android:minLines="1" android:maxLines="2"
设置省略样式` android:ellipsize=”end”包括start,end,middle,end,none和marquee(无效)
设置动态的颜色
// 16进制
textView.setColor(Color.setTextColor(Color.parseColor("#000000"));
//基于资源文件
textView.setTextColor(ContextCompat.getColor(context, R.color.your_color));
//预设的颜色
textView.setColor(Color.setTextColor(Color.RED));
自动连接:设置android:autoLink="all"
用户可以通过点击你的文字中的链接打开浏览器。
android:linksClickable="true"
在listview中这一连接是有问题的因为会与setOnItemClickListener()方法冲突,需要自定义一个需要点击的textview类代替需要点击的textview
Span类
可以改变一个TextView的风格,例如给前几个字母编程红色,后面的加一个划线
String firstWord = "Hello";
String secondWord = "World!";
TextView tvHelloWorld = (TextView)findViewById(R.id.tvHelloWorld);
// Create a span that will make the text red
ForegroundColorSpan redForegroundColorSpan = new ForegroundColorSpan(
getResources().getColor(android.R.color.holo_red_dark));
// Use a SpannableStringBuilder so that both the text and the spans are mutable
SpannableStringBuilder ssb = new SpannableStringBuilder(firstWord);
// Apply the color span
ssb.setSpan(
redForegroundColorSpan, // the span to add
0, // the start of the span (inclusive)
ssb.length(), // the end of the span (exclusive)
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // behavior when text is later inserted into the SpannableStringBuilder
// SPAN_EXCLUSIVE_EXCLUSIVE means to not extend the span when additional
// text is added in later
// Add a blank space
ssb.append(" ");
// Create a span that will strikethrough the text
StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
// Add the secondWord and apply the strikethrough span to only the second word
ssb.append(secondWord);
ssb.setSpan(
strikethroughSpan,
ssb.length() - secondWord.length(),
ssb.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// Set the TextView text and denote that it is Editable
// since it's a SpannableStringBuilder
tvHelloWorld.setText(ssb, TextView.BufferType.EDITABLE);
展示一个图片
在TextView中可以展示任意的图片
android:drawableLeft="@mipmap/ic_launcher" android:padding="5dp"
此外除了这个还可以在EditText,Button等其他子类控件中使用图片,属性有drawbleRight,drawableBottom.drawableLeft。