作家
登录

Android Coding利器之掌握小技巧,助你Coding更上一层楼~

作者: 来源: 2017-08-02 14:01:30 阅读 我要评论

  • <TextView 
  •      android:layout_width="wrap_content" 
  •     android:layout_height="wrap_content" 
  •     android:text="您须要付出:"/><TextView 
  •     android:layout_width="wrap_content" 
  •     android:layout_height="wrap_content" 
  •     android:text="¥50" 
  •     android:textColor="@android:color/holo_red_light"/>  
  • 可有简荡竽暌姑法,干嘛还多写一个TextView,这不是浪费嘛?瞧着~

    string文件中如许写:

    1. <string name="string_pay_price">您须要付出:%1$s</string> <!-- %1$s:代码第一位是String类型,同理,第二位%2$s --> 

    Activity定义办法:

    1. private void setPayPrice(String payPrice) { 
    2.     tvShow.setText(getString(R.string.string_pay_price, payPrice)); 
    3.     SpannableStringBuilder builder = new SpannableStringBuilder(tvShow.getText().toString()); 
    4.     ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.RED); // 根据请求自定义色彩值 
    5.     builder.setSpan(colorSpan, 4, tvShow.getText().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
    6.     tvShow.setText(builder); 
    7.  

    四、主动链接TextView内容,例如网址,德律风,e-mail等

    效不雅如下:

    代码部分:

    1. <TextView 
    2.     android:id="@+id/id_test" 
    3.     android:layout_width="wrap_content" 
    4.     android:autoLink="all" 
    5.     android:text="贺贺博文地址:http://blog.csdn.net/u012400885 \n萌芽德律风:13811604922" 
    6.     android:layout_height="wrap_content"/>  

    五、巧用LinearLayout,节俭不须要代码~

    下面为大年夜家附上一个简单效不雅图,大年夜家起首想想,如不雅是你,怎么写?

    TextView多的话还可以提取Style文件,代码简洁易读。

    这里为大年夜家惹人另一种写法,也就是小标题若何巧用LinearLayout

    19. Alt+J 多行编辑

    起首编写shape文件,很简单,设置高度和色彩。

    1. <shape xmlns:android="http://schemas.android.com/apk/res/android"
    2.  
    3. <size android:height="15dp"/> 
    4.  
    5. <solid android:color="#FFF000"/></shape>  

    其次,在构造文件中设置divider以及showDividers属性即可。

    1. <?xml version=

        推荐阅读

        球星们要失业?机器人在2050年可以击败专业足球队

      人工智能和机械人成长越来越快,人们也开端担心本身的工作在某一天被机械人代替。别怕,别说一般技能的工作,就是像内马尔如许的大年夜球星,也许很快都邑“掉业”了。近日,Ro>>>详细阅读


      本文标题:Android Coding利器之掌握小技巧,助你Coding更上一层楼~

      地址:http://www.17bianji.com/lsqh/36506.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)