zoukankan      html  css  js  c++  java
  • 添加设置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
    添加和设置
    ---------------------------------

  • 相关阅读:
    【转】jquery-取消冒泡
    【转】android如何浏览并选择图片 音频 视频
    ListView防止滑动变色的小技巧
    【转】 Android经验: proguard 阻碍 webview 正常工作
    【转】获取android设备 id
    【转】android 选取图片
    eclipse 配置git ssh登录
    android 开启或者隐藏软键盘
    【转】如何设置Android软键盘的默认不弹出?
    【转】中国人唯一不认可的成功——就是家庭的和睦,人生的平淡
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3109039.html
Copyright © 2011-2022 走看看