• android 样式(Style)和主题(Theme)


    样式(Style)和主题(Theme)

    开头语:在android很多地方要对控件的样式(如:ActionBar的样式)和Activity的样式进行设置,对应控件的样式设置是(Style)对Activity的样式设置是(Theme)

    API是这样来解释Style的:

      A style resource defines the format and look for a UI.A style can be applied to an individual View (from within a layout file)

       or to an entire Activity or application (from within the manifest file)

    下面就来说说怎么进行style设置:

    1.在资源文件夹里创建好style.xml和theme.xml

    2.在XML文件中都要添加一个<resources>根节点

    3.在根节点里面<style>增加一个全局唯一的名字,也可以选择增加一个父类属性,继承已有的style

    通过两个例子来说明Style和Theme

    Style:

    在Values的Style.xml中写:

    1 <!-- TextView设定的简单样式 -->
    2     <style name="TextStyle">    
    3         <item name="android:textColor">#008</item>
    4         <item name="android:textSize">18sp</item>
    5     </style>

    在MainActivity当中添加一个TextView

    1  <TextView
    2         style="@style/TextStyle"   
    3         android:layout_width="wrap_content"
    4         android:layout_height="wrap_content"
    5         android:text="我是没有改变style的TextView" />

    在没有写style="@style/TextStyle"的时候运行出来TextView的字体就是普通效果:

    再加了style="@style/TextStyle"引用style.xml定义的样式后TextView显示的字体变成了:

    则对View的样式添加成功了的

    Theme:

    现在Values.中添加一个Theme.xml文件,在Theme.xml的<Resource>根节点里面写上<Style>并定义一些样式,在ANDROID的SDK中已经定义了很多Theme。

     Theme是针对窗体级别的,改变窗体样式,如果你想对应用的所有Activity的样式进行设置就要在AndroidManifest.xml中对<Application>中添加android:theme属性

    如:

    <Application  android:theme="@style/AppTheme"></Application>即可

     若想修改指定Activity就在AndroidManifest.xml对指定Activity中添加android:theme属性

    如:

    <activity  android:theme="@style/AppTheme" ></activity>

    Android SDK定义好的一些常用theme:

    下面的前三个之外直接复制就会出错。@是说明系统已经定义过的,@android:style/  是必须带上的。

    ?android:theme="@android:style/Theme.Dialog" 

      将一个Activity显示为对话框模式
    ?android:theme="@android:style/Theme.NoTitleBar"  不显示应用程序标题栏
    ?android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不显示应用程序标题栏,并全屏
    ?android:theme="Theme.Light"  背景为白色
    ?android:theme="Theme.Light.NoTitleBar"  白色背景并无标题栏 
    ?android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏
    ?android:theme="Theme.Black"  背景黑色
    ?android:theme="Theme.Black.NoTitleBar"  黑色背景并无标题栏
    ?android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏
    ?android:theme="Theme.Wallpaper"  用系统桌面为应用程序背景
    ?android:theme="Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,且无标题栏
    ?android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏
    ?android:theme="Translucent"
    ?android:theme="Theme.Translucent.NoTitleBar" 半透明,无标题
    ?android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明,无标题,全屏
    ?android:theme="Theme.Panel" 面板风格显示
    ?android:theme="Theme.Light.Panel" 平板风格显示

  • 相关阅读:
    Tkinter之布局管理pack
    Python smtplib,email
    PyAutoGUI (2) 屏幕处理和弹框,输入中文
    键鼠操作自动化库--PyAutoGUI模块(1)
    python----->>删除超过固定天数的日志
    Transformer再下一城!Swin-Unet:首个纯Transformer的医学图像分割网络
    西门子S7-1200 PLC 水箱水位控制程序案例
    【开源】Transformer 在CV领域全面开花:新出跟踪、分割、配准等总结
    Google发布语义分割新数据集!顺带开发个模型屠榜,已被CVPR2021接收
    YOLOv5算什么,这个才是最强!---PP-YOLOv2
  • 原文地址:https://www.cnblogs.com/liangstudyhome/p/3672199.html
Copyright © 2020-2023  润新知