zoukankan      html  css  js  c++  java
  • Android学习笔记颜色资源文件

    资源文件目录

    颜色资源文件格式

    colors.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colorPrimary">#008577</color>
        <color name="colorPrimaryDark">#00574B</color>
        <color name="colorAccent">#D81B60</color>
        <color name="bg">#660000FF</color>
        <color name="title">#FF6600</color>
    </resources>
    

    在布局文件中引用颜色资源
    MainActivity.xml

      <TextView
            android:id="@+id/motto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/bg"
            android:textColor="@color/title"/>        
    

    在Java代码中引用颜色资源
    MainActivity.java

            tv_motto.setTextColor(getColor(R.color.title));
            tv_motto.setBackgroundColor(getResources().getColor(R.color.bg));
    
  • 相关阅读:
    组合模式
    过滤器模式
    桥接模式
    适配器模式
    原型模式
    建造者模式
    抽象工厂
    工厂方法
    静态工厂
    单例模式
  • 原文地址:https://www.cnblogs.com/lzpq/p/12833263.html
Copyright © 2011-2022 走看看