zoukankan      html  css  js  c++  java
  • android如何切换皮肤

    1、先定义attr文件

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <attr name="layout_bg" format="reference"/>
        <attr name="layout_item_bg" format="reference"/>
        <attr name="textColor" format="reference"/>
    </resources>

    2、定义实际的属性值文件

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="AppTheme.Default">
            <item name="layout_bg">@color/left_draw_bg</item>
            <item name="layout_item_bg">@color/window_background</item>
            <item name="textColor">@color/gray</item>
        </style>
    
        <style name="AppTheme.Green">
            <item name="layout_bg">@color/left_draw_bg</item>
            <item name="layout_item_bg">@color/window_background</item>
            <item name="textColor">@color/green</item>
        </style>
    
        <style name="AppTheme.Red">
            <item name="layout_bg">@color/left_draw_bg</item>
            <item name="layout_item_bg">@color/window_background</item>
            <item name="textColor">@color/red</item>
        </style>
    
    </resources>

    3、使用我们自定义的属性

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/layout_bg"
        android:orientation="vertical">
    <TextView
                    android:id="@+id/tv_left_title"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/s_117"
                    android:layout_marginTop="@dimen/s_117"
                    android:textColor="?attr/textColor"
                    android:text="@string/app_name" />

    通过?attr/+自定义属性名引用

    4、Activity调用相应的主题

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setTheme(R.style.AppTheme_Green);
            setContentView(R.layout.activity_main);
            initView();
        }

    可见android系统,让人先简单的使用主题,只要调用setTheme就可以搞定。

    系统将AppTheme.Green改成了AppTheme_Green来调用。

  • 相关阅读:
    R语言爬虫:CSS方法与XPath方法对比(代码实现)
    R语言爬虫:Rvest包函数介绍(表格)
    R语言爬虫:使用R语言爬取豆瓣电影数据
    R语言学习笔记(二十二):字符串处理中的函数对比(代码实现)
    R语言学习笔记(二十一):字符串处理中的元字符(代码展示)
    history命令详解
    文件服务器:FTP服务器详解
    Linux下的DOS攻击
    Linux-/proc目录简介
    Linux-详解inode节点
  • 原文地址:https://www.cnblogs.com/jiduoduo/p/5238514.html
Copyright © 2011-2022 走看看