• 添加设置Android编程心得为TextView添加各种样式


    PS:今天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘。目前又不当COO,还是得用心记代码哦!

        在开发过程当中,本人发现有时候TextView须要特殊显示的时候,须要特殊处置,现将我的代码记载如下

        

        1.为TextView 添加下划线

    TextView appVersion=(TextView) root.findViewById(R.id.appversion_value);
    	appVersion.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    		appVersion.setText("Ver 1.2.5");

        如上代码这样就为这样一个代码添加了下划线

        

        

        2.为TextView添加超链接

    String blogsite="http://blog.csdn.net/yangqicong11";
    	       SpannableString spblog =  new  SpannableString( blogsite);      
    	        //设置超链接   
    	       spblog.setSpan( new  URLSpan( blogsite ),  0 , blogsite.length() ,   
    	               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);    
    	       PersonalBlog=(TextView) root.findViewById(R.id.PersonalBlog_value);
    	       PersonalBlog.setText(spblog);
    	       PersonalBlog.setMovementMethod(LinkMovementMethod.getInstance());

        这样我们的TextView就成了超链接的情势,用户点击后可以直接调用浏览器跳转到对应页面

        

        3.为TextView  添加背景高亮显示

        

    String tmp= "背景高亮";
            SpannableString sp =  new  SpannableString( "背景高亮" );   
            //设置高亮款式一   
           sp.setSpan( new  BackgroundColorSpan(Color.BLUE),  0  , tmp.length() ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);   
    
    	TextView appEditor=(TextView) root.findViewById(R.id.appEditor_value);
    		appEditor.setText(sp);
        每日一道理
    时间好比一条小溪,它能招引我们奔向生活的海洋;时间如同一叶扁舟,它将帮助我们驶向理想的彼岸;时间犹如一支画笔,它会指点我们描绘人生的画卷。

        这样我们的TextView 背景就变成高亮了

        

        4.为TextView 添加文字高亮显示

    String tmp= "文字高亮";
            SpannableString sp =  new  SpannableString( "文字高亮" );   
            //设置高亮款式二   
           sp.setSpan( new  ForegroundColorSpan(Color.YELLOW), 0 , tmp.length() ,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);   
    	TextView appEditor=(TextView) root.findViewById(R.id.appEditor_value);
    		appEditor.setText(sp);

        与上一个所不同的是 这里仅仅只是TextView中的文字产生了高亮的效果

        

        

    5.为TextView添加加粗斜体显示

        

    String tmp= "设置斜体";
            SpannableString sp =  new  SpannableString( "设置斜体" );   
            //设置斜体   
           sp.setSpan( new  StyleSpan(android.graphics.Typeface.BOLD_ITALIC),  0 ,  tmp.length() , Spannable.SPAN_EXCLUSIVE_INCLUSIVE);   			
    	TextView appEditor=(TextView) root.findViewById(R.id.appEditor_value);
    	appEditor.setText(sp);

        

        

        

        

        

    文章结束给大家分享下程序员的一些笑话语录: 这年头的互联网真是娱乐了中国,网民们从各种各样的“门”里钻来钻去,又有好多“哥”好多“帝”,值得大家品味不已……网络经典语录,关于IT与互联网,经典与您分享!

    --------------------------------- 原创文章 By
    添加和设置
    ---------------------------------

  • 相关阅读:
    论分治与归并思想
    关于缩短cin时间的方法
    【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)模版】
    getDomain(url)-我的JavaScript函数库-mazey.js
    jQuery-PHP跨域请求数据
    ASP-Server.Transfer-Response.Redirect
    jQuery获取相邻标签的值
    分界线<hr/>
    jQuery获取input复选框的值
    Bootstrap支持的JavaScript插件
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3109039.html
Copyright © 2020-2023  润新知