android学习之-Style样式的定义

这个例子主要是写了配置文件,main.xml

 
 
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:orientation="vertical" 
  4.     android:layout_width="fill_parent" 
  5.     android:layout_height="fill_parent" 
  6.     > 
  7. <TextView   
  8.     android:layout_width="fill_parent"  
  9.     android:layout_height="wrap_content"  
  10.     android:text="@string/str_text_view1" 
  11.     style="@style/StyleText1" 
  12.     android:gravity="center_vertical|center_horizontal" 
  13.     /><!-- 水平垂直居中对齐 --> 
  14. <TextView   
  15.     android:layout_width="fill_parent"  
  16.     android:layout_height="wrap_content"  
  17.     android:text="@string/str_text_view2" 
  18.     style="@style/StyleText2" 
  19.     android:gravity="center_vertical|center_horizontal" 
  20.     /> 
  21. </LinearLayout> 

定义要用到的样式style.xml

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <resources> 
  3. <style name="StyleText1"> 
  4.     <item name="android:textSize">18sp</item> 
  5.     <item name="android:textColor">#EC9237</item> 
  6. </style> 
  7. <style name="StyleText2"> 
  8.     <item name="android:textSize">14sp</item> 
  9.     <item name="android:textColor">#FF7F7C</item> 
  10.     <item name="android:fromAlpha">0.0</item> 
  11.     <item name="android:toAlpha">0.0</item> 
  12. </style> 
  13. </resources> 

有没有发现style.xml的定义方式与color.xml很相似呢,引一下color.xml的定义

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <resources> 
  3. <color name="white">#ffffff</color> 
  4. <color name="black">#000000</color> 
  5. <drawable name="red">#ff0000</drawable> 
  6. <drawable name="blue">#0000ff</drawable> 
  7. </resources> 

对比一下可以更深的加强记忆,其它的代码还是见附件



本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/742957,如需转载请自行联系原作者

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值