首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android式样与主题

2013-07-04 
Android样式与主题android样式,主题设置心得 http://zhy584520.iteye.com/blog/11682271. android style样

Android样式与主题
android样式,主题设置心得 http://zhy584520.iteye.com/blog/1168227
1. android style样式的设置.先看下面一段设置字体与文字颜色的样式文件


同样的,item项中的name属性值是来源于android系统android.R.attr.windowNoTitle。不过得注意style里parent属性值是android系统自带的主题,这些值是来源于android.R.style.Theme_Black,这里的android.R.style.Theme_Black在主题文件里设置是对应android:Theme.Black,所有的其它自带主题都是差不多这样设置。_换成.就OK。

Android样式 http://www.eoeandroid.com/thread-18928-1-1.html
android中的样式和CSS样式作用相似,都是用于为界面元素定义显示风格,它是一个包含一个或者多个view控件属性的集合。如:需要定义字体的颜色和大小。

在Android中可以这样定义样式:
在res/values/styles.xml文件中添加以下内容


在layout文件中可以像下面这样使用上面的android样式:

<style>元素中有一个parent属性。这个属性可以让当前样式继承一个父样式,当前样式可以继承到父样式的值。当然,如果父样式的值不符合你的需求,你也可以对它进行修改,如下:
 

android中主题也是用于为应用定义显示风格,它的定义和样式的定义相同,如下:

上面“?android:windowNoTitle”中的问号用于引用在当前主题中定义过的资源的值。下面代码显示在AndroidManifest.xml中如何为应用设置上面定义的主题:


除了可以在AndroidManifest.xml中设置主题,同样也可以在代码中设置主题,如下:
?android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
?android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
?android:theme="@android:style/Theme.Light" 背景为白色
?android:theme="@android:style/Theme.Light.NoTitleBar" 白色背景并无标题栏
?android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
?android:theme="@android:style/Theme.Black" 背景黑色
?android:theme="@android:style/Theme.Black.NoTitleBar" 黑色背景并无标题栏
?android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
?android:theme="@android:style/Theme.Wallpaper" 用系统桌面为应用程序背景
?android:theme="@android:style/Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
?android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
?android:theme="@android:style/Translucent" 半透明
?android:theme="@android:style/Theme.Translucent.NoTitleBar" 半透明、无标题栏
?android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
?android:theme="@android:style/Theme.Panel"
?android:theme="@android:style/Theme.Light.Panel"

这些主题可以应用到整个应用Application范围或者某个活动Activity范围中。

应用Application范围
在AndroidManifest.xml中的application节点中设置theme属性,主题theme应用到整个应用程序中。

活动Activity范围
使用java代码或者在AndroidManifest.xml中对活动Activity的主题进行设置,主题仅应用到当前活动中。
在AndroidMainifest.xml设置方法:
使用java代码进行设置,在当前活动Activity的onCreate中进行设置:
@Overridepublic void onCreate(Bundle savedInstanceState){   super.onCreate(savedInstanceState);   setTheme(android.R.style.Theme_Translucent_NoTitleBar);   setContentView(R.layout.main);}

热点排行