zoukankan      html  css  js  c++  java
  • Android TextView 显示富文本、图片、点击文字跳转自定义界面

    //显示富文本
    String html="<font color='red'>样式一</font> <br>"; html+="<font color='#0000FF'> <big> <i> 样式二 </i> </big> <font>"; html+="<font color='@"+android.R.color.white+"'> <tt> <b> <big> <u> 样式三 </u> </big> </b> </tt> </font> <br>"; html+="<big> <a href='http://blog.csdn.net/a_mean'>我的博客:http://home.cnblogs.com/u/lrfsmile/ </a> </big>"; CharSequence charsequence=Html.fromHtml(html); tv.setText(charsequence);

    //显示图片
    Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.test);
            ImageSpan imagespan=new ImageSpan(this, bitmap);
            SpannableString spannableString=new SpannableString("icon");
            spannableString.setSpan(imagespan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv.setText(ss);


    //点击文字跳转到自定义界面
    String str="点击显示自定义Activity";
           SpannableString  spannableString=new SpannableString(str);
           spannableString.setSpan(new ClickableSpan() {
            @Override
    //单击时要执行的动作
            public void onClick(View widget) {
                // TODO Auto-generated method stub
                Intent intent=new Intent(MainActivity.this, Activity1.class);
                startActivity(intent);
                
            }
        }, 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
           tv.setText(spannableString);
           //再单击链接时凡是要执行的动作都必须设置MovementMethod对象
           tv.setMovementMethod(LinkMovementMethod.getInstance());

     

  • 相关阅读:
    网络编程基础
    windows下配置chromedriver
    Selenium和PhantomJS
    爬虫之正则表达式re模块
    Fiddler抓包工具总结
    使用jquery刷新当前页面
    关于requests.exceptions.ConnectionError: HTTPSConnectionPool的问题
    python的urllib学习
    安卓---Tabhost实现页面局部刷新--父页子页之间的传值
    安卓---右滑返回
  • 原文地址:https://www.cnblogs.com/lrfsmile/p/3830988.html
Copyright © 2011-2022 走看看