zoukankan      html  css  js  c++  java
  • Android-主题

    主题分为两种:

      

       第一种:使用Android系统提供的主题

         第二种:自己定义主题

    样式 与 主题 区分理解

    样式是控制(View的子类风格)控件风格 或者 是(ViewGroup的子类风格)布局风格

    主题是控制整体风格(例如:Application  Activity 等)


    Android系统提供的主题:

    Activity使用Android系统提供的主题:


    Application 默认就使用来一个主题:android:theme="@style/AppTheme"

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">

    Activity 使用系统的主题:

         <!--
                对话框主题
                android:theme="@android:style/Theme.DeviceDefault.Dialog">
                android:theme="@android:style/Theme.Holo.Dialog"
                android:theme="@android:style/Theme.Dialog"
    
                android:theme="@style/Theme.AppCompat.Dialog"
                android:theme="@style/Theme.AppCompat.DayNight.Dialog"
                android:theme="@style/Base.Theme.AppCompat.Dialog.FixedSize"
                ...
    
                没有标题+全屏
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
    
                没有标题
                android:theme="@android:style/Theme.Black.NoTitleBar"
    
            -->
        <activity android:name=".ThemeActivity"
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    
            </activity>

    使用Android系统主题的效果:


    自定义主题:

    自己去定义主题,首先要找到系统提供的主题文件

    android-16 android-22 android-xxx 平台版本无所谓,都可以的

    找到themes.xml文件打开阅读

    找到themes.xml文件打开阅读,要明白Android的这些窗体都是Window,所以直接找Window字样

    在values文件夹新建,themes.xml 主题文件:

    在themes.xml中定义主题,注意:自定义主题需要增加 android:才行,刚刚阅读系统主题是没有加android: 。

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <!-- 无标题主题 -->
        <style name="My_Theme_Not_Title">
            <item name="android:windowNoTitle">true</item>
        </style>
    
        <!-- 全屏主题(无状态栏 + 继承了parent="My_Theme_Not_Title" 无标题) -->
        <style name="My_Theme_Not_Title_Fullscreen" parent="My_Theme_Not_Title">
            <item name="android:windowFullscreen">true</item>
        </style>
    
    </resources>

    使用自定义主题:

    自定义主题:
                android:theme="@style/My_Theme_Not_Title_Fullscreen"
                android:theme="@style/My_Theme_Not_Title"
        <activity android:name=".ThemeActivity"
                android:theme="@style/My_Theme_Not_Title">
    
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    
            </activity>

    自定义主题都效果:

  • 相关阅读:
    (DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device【转】
    Linux 内核虚拟地址到物理地址转换讨论【转】
    【Go命令教程】6. go doc 与 godoc
    【Go命令教程】5. go clean
    【Go命令教程】4. go get
    PHP项目收藏
    【Go命令教程】3. go install
    分享下使用 svn,测试服务器代码自动更新、线上服务器代码手动更新的配置经验
    【Go命令教程】2. go build
    【Go命令教程】1. 标准命令详解
  • 原文地址:https://www.cnblogs.com/android-deli/p/10100528.html
Copyright © 2011-2022 走看看