android中的样式和主题
有的时候我们一个页面要用很多个textview,而且这些textview的样式非常相像,这种情况下我们可以把这些样式抽取出来,然后在每个textview中引用即可,这样修改起来也方便。
我们来看一个简单的例子,在一个页面中有三个textview,每个textview显示内容不同但是样式都相像,先来看看显示效果:
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.style.MainActivity" >
<TextView
style="@style/tv_style"
android:text="纵豆蔻词工,青楼梦好,难赋深情。" />
<TextView
style="@style/tv_style_g"
android:text="二十四桥仍在,波心荡、冷月无声。" />
<TextView
style="@style/tv_style.tv_style_b"
android:text="念桥边红药,年年知为谁生。" />
</LinearLayout>
布局中的textview很简洁,因为我们把显示样式都抽取出来了,看看样式:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light" />
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme" />
<style name="tv_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">25sp</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="tv_style_g" parent="tv_style">
<item name="android:textColor">#00FF00</item>
</style>
<!-- 两种不同的继承方式 -->
<style name="tv_style.tv_style_b">
<item name="android:textColor">#0000FF</item>
</style>
</resources>
tv_style是一个总的样式,定义了每个textview的宽高,字体大小以及字体颜色,tv_style_g和tv_style_b是继承自tv_style样式,继承之后覆盖了tv_style中的颜色,其他都不变,这里有两种继承方式。
android中的样式文件可以用于任何控件,包括button,imageview等。
这是控件的样式,应用的主题我们也可以自己设置:
在AndroidManifest.xml文件中,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.style"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
android:theme=”@android:style/Theme.Translucent”表示应用的主题,Translucent表示是透明的,效果如图:
打开应用后就是这种效果。
还有一种是Dialogandroid:theme="@android:style/Theme.Dialog,这个表示是以对话框的形式显示,效果如图:
还有很多种,看官自己去试吧。
android中的样式和主题的更多相关文章
- android中的样式主题和国际化
一.Android中的样式和主题 1.1样式 样式是作用在控件上的,它是一个包含一个或者多个view控件属性的集合.android style类似网页设计中的css设计思路,可以让设计 ...
- [android] 安卓自定义样式和主题
简单练习自定义样式和主题,样式是加在View上,主题是加在Application或者Activity上 styles.xml <?xml version="1.0" enco ...
- Android中EditText样式修改 聚焦光标、背景
在Android开发中,根据项目的需求,需要定制一些特殊的样式,例如:使用EditText时,聚焦时的背景及光标图片使用自定义而非android系统默认的.这两天,在项目中涉及此需求,现记录如下: 首 ...
- Android下Notification,样式style,主题theme的功能实现
一:Notification 1.NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVIC ...
- Android中Context样式分析
目录 1.样式定义以及使用 1.1.默认样式 1.2.样式定义及使用 1.3.当前样式下attr属性的获取 1.4.属性集合的定义与获取 2.Activity中Theme的初始化流程 2.1.系统调用 ...
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...
- Android中为窗口定义主题
在res/values/styles文件夹中定义如下: <style name="myTheme"> <item name="android:windo ...
- android 中theme样式的解释
android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式 android:theme="@androi ...
- Android 样式和主题(style & theme)
Android 样式 android中的样式和CSS样式作用相似,都是用于为界面元素定义显示风格,它是一个包含一个或者多个view控件属性的集合.如:需要定义字体的颜色和大小. 在CSS中是这样定义的 ...
随机推荐
- IntelliJ IDEA Subversion的使用方式
接着一直点下一步基本上就可以了
- C++控制台程序中使用定时器
转自博客:http://www.cnblogs.com/phinecos/archive/2008/03/08/1096691.html 作者:洞庭散人 “我现在项目是一个控制台程序,用到的Win32 ...
- 利用if else 判断方程有几个根
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; ...
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- response常见应用、response细节、输出随机图片、定时刷新网页
response常见应用 向客户端输出中文数据 分别以OutputStream和PrintWriter输出 多学一招:使用HTML语言里面的<meta>标签来控制浏览器行为 思考:用O ...
- MFC如何获取编辑框中输入的内容
1.GetDlgItemText() 2.先用 GetDlgItem(编辑框的ID)获取指向编辑框的指针.再用GetWindowText函数将获取内容保存至指定的字符数组里. 3.使用 GetDlgI ...
- jQuery 参考手册 - 效果
(speed可选:规定动画的速度.默认是 "normal",可能的值:毫秒(比如 1500)"slow""normal""fast ...
- Stand-up meeting
A stand-up meeting (or simply "stand-up") is a daily team-meeting held to provide a status ...
- The server does not support version 3.1 of the JEE Web module specification.
使用MyEclipse2015打开MyEclipse2014编辑的项目,在服务器Tomcat 7部署时,提示"The server does not support version 3.1 ...
- c语言数据处理!
#include "stdio.h" struct { ]; long nume; ]}; ]; float score; }stur; main() { printf(" ...