Android主题theme和样式style总结

        Android中的theme和style对页面的效果影响还是很大的,有的程序启动后页面的背景颜色为白色,字体为黑色,但是有的程序又是相反的,这是因为Android默认的主题显示不一样,各个编辑工具对主题和样式的默认设置有时候是不一样的,所以导致了刚开始的效果不一样。
        主题theme和样式style既可以设置默认窗体的样式、字体的大小和颜色,还可以设置是否显示标题栏或设置标题栏的文字大小、颜色和背景,甚至隐藏标题栏或状态栏。
        注意标题栏和状态栏是不一样的,标题显示的是App的名称和图标,状态栏显示的是手机的电量、信号等数据,两者都是可以隐藏的。
Android主题theme和样式style总结_第1张图片
        设置主题和样式,既可以对整个App设置也可以对单个页面(Activity)设置。如果有相同的属性,Activity中的属性会覆盖掉Application中的。

示例:对整个App设置

 "@string/app_name" android:icon="@drawable/heart"                 android:name=".config.MyApplication"                 android:theme="@style/BaseStyle"            >

对单个页面设置:

      ".activity.MyActivity"                  android:label="@string/app_name"                  android:theme="@style/MyStyle"                >

当然style属性的设置要在res中的values文件夹中的styles文件(没有就要自己创建)

比如:

             

        Style中不仅可以设置很多属性还可以设置对齐方式!有些属性是设置具体值,有些属性是设置true或false的值。

下面是一些属性的列举供大家参考:

下面是一些android自带的属性(可以直接在Application或Activity中设置):

android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式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/Theme.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" : 平板风格显示

使用:

   "@string/app_name" android:icon="@drawable/heart"                 android:name=".config.MyApplication"                 android:theme="@android:style/Theme.NoTitleBar"             >

        这时默认所有的页面都是没有标题栏的。不要忘记前面的android:,因为这个是android系统提供的。

        但是要注意一个Application或Activity只能设置一个theme,如果要设置多个样式的值还是要设置style!

        下面是style的设置,其中style的name是可以自己定义的,需要拿来调用,而item的name是固定的,是android中已经定义好的。你会发现所有item的name都是android:下的!
        一个sytle中        可以有一个或多个item的属性的设置。

Style样式XML文件(存放在res/values/):

<?xml version="1.0" encoding="utf-8"?><resources><style name="CustomText" parent="@style/Text"><item name="android:textSize">20spitem><item name="android:textColor">#008item>style>resources>

        同样可以应用以上样式到TextView的XML文件(存放在res/layout/):

<?xml version="1.0" encoding="utf-8"?><EditTextstyle="@style/CustomText"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Hello, World!" />

        Style还可以对布局或控件(LinearLayout、TextView、ImageView等等)进行设置,比如多个TextView有相同的属性就可以抽成一个style,对这多个TextView设置style,就相当于设置了多个属性!

Style中item属性详解:

对Window的属性:

android:windowNoTitle 设置有没有标题栏true|falseandroid:windowFullScreen 设置全屏true|falsedroid:windowIsFloating 设置是否浮现在activity之上true|falseandroid:windowIsTranslucent 设置window是否为透明android:windowBackground 设置window的背景颜色android:windowContentOverlay这个是定义contentoverlay的背景的

常见的:TextView的Style

android:textSize 设置字体大小android:textColor 设置字体颜色android:textColorHighlight 被选中文字的底色,默认为蓝色android:textColorHint 设置提示信息文字的颜色,默认为灰色。与hint一起使用。android:textColorLink 文字链接的颜色android:textFilterEnabled 设为真时,列表会过滤根据用户的要求,过滤结果集。列表的适配器必须实现了 Filterable接口,才能使其可用android:background 设置背景颜色(值可以是图片,也可以是十六进制颜色值)android:textAppearance 设置文字的外观,如“android:textAppearance=“?android:attr/textAppearanceLargeInverse”这里引用的是系统自带的一个外观android:textOff 未选中时按钮的文本android:textOn 选中时按钮的文本android:textStyle 字体,bold, italic, bolditalicandroid:textScaleX控制字与字之间的间距

        上面只是一些知识的收集罗列,有很多我也是没有用过的,遇到不懂的可以一起讨论。
        本文主要是相对theme的介绍!

去掉所有Activity界面的标题栏
修改AndroidManifest.xml
在application 标签中添加android:theme=”@android:style/Theme.NoTitleBar”

补充一下;上面使用亮色背景,有时候弹出的对话框背景还是黑的,需要设置的属性是:
android:theme=”@android:style/Theme.Holo.Light”
Holo表示整天的意思。还有其他和Holo相关的属性就不一一罗列了。

更多相关文章

  1. Android 软键盘在有scollview,纵向viewpager+recyclview实现列表,
  2. android背景选择器selector用法小结
  3. android设置按钮背景透明度与设置布局背景图片的透明度
  4. android默认属性
  5. 将Android DHCPInfo 属性转换为int类型(使用BigInteger)

随机推荐

  1. 微软大数据领域优势分析
  2. 华纳云:香港IP地址更换需要注意的事项
  3. 大数据仓库-kudu
  4. PDO连接数据库实例
  5. es软件安装
  6. 最新个税计算、个税倒推和税后倒推公式
  7. 最新Excel个税计算公式来了,说说你每月该
  8. 一网打尽:算术平均、修剪平均和条件平均值
  9. Excel按区间查询,大咖有句悄悄话
  10. Linux必会技能