• Android学习笔记主题(Theme)资源文件


    安卓的主题资源文件,可以用于对Android应用的美化。

    styles文件是主题资源文件。
    定义一个主题资源格式如下:

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
        <style name="bgTheme" parent="@style/AppTheme">
            <item name="android:windowNoTitle">false</item>
            <item name="android:windowBackground">@drawable/bg</item>
        </style>
    </resources>
    

    引用主题资源可以在AndroidManifest资源中通过 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引用

        <activity android:name=".MainActivity"
                android:theme="@style/bgTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
         </activity>
    

    还可以通过Java代码引用

        setTheme(R.style.bgTheme);
        setContentView(R.layout.activity_main);
    

    注意:如果使用Java代码应用要写在 setContentView(R.layout.activity_main) 之前

  • 相关阅读:
    工作中碰到的小问题记录
    MySQL之路 ——1、安装跳坑
    C# 构造函数
    C# 操作文件类,文件夹存在判断,创建,文件内容读写。
    你为什么(不)用存储过程?
    C#基础巩固之基础类型
    mysql存储过程中使用事务
    Redis 安装
    Maven 国内映像
    mysql存储过程详解
  • 原文地址:https://www.cnblogs.com/lzpq/p/12885237.html
Copyright © 2020-2023  润新知