Android中TextView不能识别电信号码11888的问题。

http://androidren.com/index.php?qa=398&qa_1=android%E4%B8%ADtextview%E4%B8%8D%E8%83%BD%E8%AF%86%E5%88%AB%E7%94%B5%E4%BF%A1%E5%8F%B7%E7%A0%8111888%E7%9A%84%E9%97%AE%E9%A2%98

<TextView
    android:id="@+id/xxx_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="24dp"
    android:layout_marginRight="24dp"
    android:layout_marginTop="16dp"
    android:autoLink="email|phone|web"
    android:gravity="left"
    android:linksClickable="true"
    android:text="拨打 11888."
    android:textColor="#393939"
    android:textColorLink="#112233"
    android:textSize="15sp"
    android:visibility="visible" />

布局文件中如上设置,预览的时候可以识别出11888. 但真机运行缺不能识别。

最后只能在代码中手动设置才能解决。

SpannableString spanableInfo = new SpannableString(
        "拨打 11888");
spanableInfo.setSpan(new Clickable(), 3, 8,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
telTextView.setText(spanableInfo);
telTextView.setAutoLinkMask(Linkify.ALL);
telTextView.setMovementMethod(LinkMovementMethod.getInstance());

 

class Clickable extends ClickableSpan {

    public Clickable() {
        super();
    }
    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setColor(getResources().getColor(R.color.color_red));
        ds.setUnderlineText(true);
    }
    @Override
    public void onClick(View v) {
        Intent sIntent = new Intent(Intent.ACTION_DIAL);
        Uri uri=Uri.parse("tel:11888");
        Intent intent=new Intent();
        intent.setData(uri);
        startActivity(sIntent);
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值