如何创建自定义主题,并用它在Android应用 [英] how to create a custom theme and use it in android application

查看:141
本文介绍了如何创建自定义主题,并用它在Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建自定义主题,并用它在code?在菜单中如何实现主题的选择和申请活动呢?

How to create a custom themes and use it in the code? in menu how to implement theme option and apply for the activity?

什么想法?

推荐答案

有一个很好的样式和主题指南对Android开发者网站。基本上你需要做的是

There's a nice Styles and Themes guide on the android developers site. Basically what you need to do is

  1. 定义样式(或继承内置一):

<样式名称=Theme.MyGreenTheme父=Theme.Light>     <项目名称=机器人:windowBackground>#11aa22< /项目> < /风格>

<style name="Theme.MyGreenTheme" parent="Theme.Light"> <item name="android:windowBackground">#11aa22</item> </style>

的风格应该是&LT内部投入;资源&GT; 标签中的XML资源。这是很有用的名称的资源文件的themes.xml ,以便更容易认识到什么这些样式用于

The style should be put inside a <resources> tag in an xml resources. 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

  • 将活动/应用主题,在manifest文件 - &LT;活动机器人:主题=@风格/ Theme.MyGreenTheme/&GT;
  • 或动态设置 - 使用Activity类的相应设置 - 的 setTheme()
  • set the Activity/Application theme in the manifest file - <activity android:theme="@style/Theme.MyGreenTheme"/>
  • or set it dynamically - use the corresponding setter of the Activity class - setTheme().

这篇关于如何创建自定义主题,并用它在Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆