EditText和TextView小知识

参考:http://guides.codepath.com/android/Working-with-the-TextView#using-custom-fonts
1. 限制行数android:singleLine="true"
android:lines="1"

2. 限制输入android:inputType="number"
android:digits="01"android:maxLength="5"
只能输入数字并且只能输入01和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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值