zoukankan      html  css  js  c++  java
  • 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) 之前

  • 相关阅读:
    tcpip协议
    Linux特殊文件使用原理
    shell之常用内置变量
    SSM框架CRUD小案例
    个人博客开发笔记
    蓝天筹项目开发记录
    二叉平衡树AVL的插入与删除(java实现)
    二叉搜索树(java实现)
    树的基本操作
    SQL连接
  • 原文地址:https://www.cnblogs.com/lzpq/p/12885237.html
Copyright © 2011-2022 走看看