如何创建自定义主题并在Android应用程序中使用它?
如何创建自定义主题并在代码中使用它?
How to create a custom themes and use it in the code?
在菜单中如何实现主题选项并申请活动?
In menu how to implement theme option and apply for the activity?
有一个不错的样式和主题指南" .基本上你需要做的是
There's a nice Styles and Themes guide on the android developers site. Basically what you need to do is
- 定义样式(或继承内置样式一).定义样式
- Define a style (or inherit a built-in one). To define a style
将XML文件保存在项目的
res/values/
目录中.这XML文件的名称是任意的,但必须使用.xml
扩展名并保存在res/values/
文件夹中.
save an XML file in the
res/values/
directory of your project. The name of the XML file is arbitrary, but it must use the.xml
extension and be saved in theres/values/
folder.
XML文件的根节点必须是< resources>
.
The root node of the XML file must be <resources>
.
对于要创建的每种样式,在文件中添加一个元素带有唯一标识样式的名称(此属性为必填).
For each style you want to create, add a element to the file with a name that uniquely identifies the style (this attribute is required).
即
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyGreenTheme" parent="Theme.Light">
<item name="android:windowBackground">#11aa22</item>
</style>
</resources>
将资源文件命名为 themes.xml
很有用,因此更容易识别这些样式的用途.
It's useful to name the resource file themes.xml
so it's easier to recognize what those styles are used for.
-
将定义的样式应用于活动或查看您想要的风格化.您可以
Apply the defined style to the activity or view that you want stylized. You can either
- 在清单文件中设置活动/应用程序"主题:
<活动android:theme ="@ style/Theme.MyGreenTheme"/>
- 或动态设置-使用Activity类的相应设置器- 查看更多