Android主题相关(初探)

xiaoxiao2021-02-27  176

对话框主题:

<activity android:theme="@android:style/Theme.Dialog">

继承父颜色

<activity android:theme="@android:style/Theme.Translucent">

自定义的:文件存在于 /res/values/styles.xml:

<activity android:theme="@style/CustomTheme">

主题对整个app起作用,放到appliction中

<application android:theme="@style/CustomTheme">

更多详见: Styles and Themes (官方指导)。今天先略记录一下。

一、先说说样式:

样式可以针对于view,可以针对activity,可以针对application

1、样式的继承:

继承现有样式的属性,然后只定义您想要更改或添加的属性

1)、继承自系统的内建样式:

需要写parent,例如:

<style name="GreenText" parent="@android:style/TextAppearance">         <item name="android:textColor">#00FF00</item>     </style> 2)、继承自自己写的样式:

直接包含自己写的  父样式.子样式   

<style name="CodeFont.Red">         <item name="android:textColor">#FF0000</item>     </style> 样式总览:   R.attr   可以在这里查看

二、Theme:

这个是针对application的,也可以针对activity,但是对view不起作用

一般都是请在 R.attr 参考资料中查看有关以 window 开头的属性的

R.styleable.Theme 提供了可在主题中使用的标准属性的列表。

附上源码:

Android 样式 (styles.xml)Android 主题 (themes.xml)

转载请注明原文地址: https://www.6miu.com/read-13047.html

最新回复(0)