Android 下style和theme的用法
2015-03-17 19:29
239 查看
Android中的style可以被多个界面共用,所以它适合为应用做一些基础的外观设置,可以使应用的外观既统一又容易修改。style的用法为:1.在values文件夹下新建一个style.xml文件2.在style.xml文件中来设置android各个组件的属性。style节点有三个属性值,分别是
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </style> <style name="content_demo"> <item name="android:layout_height">wrap_content</item> <item name="android:layout_width">wrap_content</item> <item name="android:textColor">#ff2376</item> <item name="android:textSize">30sp</item> <item name="android:background">#448811</item> </style> <style name="content_demo_child" parent="content_demo"> <item name="android:textColor">#000000</item> </style> </resources>name item 和 parent.name属性来设置style的名称;item属性来设置Android组建的属性;parent属性来设置style之间的继承关系,也就是说一个style可以完全得到另一个style的全部设置。并且子style可以复写父style的属性。3.在layout.xml中,给需要使用样式的组建引入所需的style即可。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView style="@style/content_demo" android:text="我是第一个" /> <TextView style="@style/content_demo" android:text="我是第二个" /> <TextView style="@style/content_demo" android:text="我是第三个" /><TextView style="@style/content_demo_child" android:text="我是第四个" /> </LinearLayout>
theme和style没有什么区别,一个使用上比较大的区别就是,style主要是用来修饰Android的View的,而theme则主要是用来修饰Android的activity的。
如果想让某个主题修饰整个应用中所有的activity,只要把该theme设置到AndroidManifest.xml文件中的application节点下即可。
相关文章推荐
- Android中的style和theme的用法
- Android入门之Style与Theme用法实例解析
- Android Style、Theme基本用法
- android之theme和style
- Android中style和theme巧用:Android应用程序启动时背景画面的切换
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- StylesheetTheme, Theme的用法
- android的theme的用法
- Android中Style和Theme的使用
- Android风格与主题(style and theme)
- Applying Styles and Themes - 应用Style和Theme - Android官方文档中文翻译
- android风格和主题程序编写–style & theme
- Android入门第十六篇之Style与Theme
- android基础---样式和主题(style&theme)
- Android中的样式和主题(style & theme)
- Android入门第十六篇之Style与Theme
- Android中theme的用法
- android UI进阶之style和theme的使用
- android全屏设置代码:android:theme="@android:style/Theme.NoTitleBar.Fullscreen"