使用样式
1.通过HTML标记,可以在字符串资源中直接使用HTML标记来达到修改样式,如
<string name="text"><i>Hello</i> <b>World</b></string>

2.通过代码方式(Spannable对象)修改样式.
获得TextView的Spannable对象的方法是先setText("something", TextView.BufferType.SPANNABLE), 然后使用getText()即可返回Spannable对象.
EditText et = (EditText)findViewById(R.id.et);et.setText("hello world");Spannable spn = (Spannable) et.getText();spn.setSpan(new BackgroundColorSpan(Color.RED), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);spn.setSpan(new StyleSpan(android.graphics.Typeface.BLOD_ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);


3.通过XML来创建公用的样式文件
在/res/values/下创建一个XML文件如下:
<?xml version="1.0" encoding="utf-8"?> <resources>     <style name="errorText">         <item name="android:layout_width">match_parent</item>         <item name="android:layout_height">wrap_content</item>         <item name="android:textColor">#ff0000</item>         <item name="android:typeface">monospace</item>     </style> </resources>

需要使用的时候就直接使用errorText这个资源id就行了
样式树,当我想基于上面的errorText样式来创建一个子样式时可以如下:ger继承了errorText的样式,并新增了textStyle属性.
不过,上述方式不适用与继承Android提供的样式,如果要继承Android提供的样式,需要使用parent属性,如下所示:
<?xml version="1.0" encoding="utf-8"?> <resources>     <style name="CustomTextAppearence" parent="@android:style/TextAppearance">         <item ......./>     </style> </resources>



Theme
Theme实际上就是Style的广泛应用.
如果要制定Theme需要在AndroidManifest.xml中设置,如下:
<activity android:theme="@style/MyTheme"/><application android:theme="@style/MyTheme"/><application android:theme="@android:style/Theme.NoTitleBar"/>

更多相关文章

  1. Android属性动画---Property Animation(四)
  2. Android中Sqlite使用初步
  3. Android中Activity启动过程探究
  4. Android学习之SharedPreferences
  5. Android(安卓)Application 对象介绍
  6. JS复制各种链接
  7. [置顶] java/android 设计模式之单例模式
  8. android EditText 下划线样式
  9. Android学习笔记16:Button控件图文混排效果的实现

随机推荐

  1. Android技术周报190310期 —— onSaveIns
  2. This Android SDK requires Android Deve
  3. 如何发布你的Android应用程序
  4. vs2010开发android的准备工作
  5. Android Studio vs. Eclipse ADT Compari
  6. Professional Android 2 Development - 5
  7. EditText不显示光标的解决方法
  8. Android项目中图标的更改
  9. android XML转义字符 常用几个 网上找到
  10. android 获取md5值 google map key申请