zoukankan      html  css  js  c++  java
  • 更改TextView文字颜色——引用color.xml中的颜色常数

    res/values/color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="green">#ff00ff00</color>
    </resources>

    res/drawable/mail.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        android:id="@+id/tv"/>
    </LinearLayout>

    src/EXT03_04.java

    package gphone.ex03_04;
    
    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class EX03_04 extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Resources resources=this.getBaseContext().getResources();
            int green=resources.getColor(R.color.green);
            TextView tv=(TextView)this.findViewById(R.id.tv);
            tv.setTextColor(green);
        }
    }
  • 相关阅读:
    时间记录日志
    软件工程作业02
    个人学习进度(第二周)
    《大道至简》第二章读后感
    《大道至简》第一章读后感
    构建之法阅读笔记02
    构建之法阅读笔记01
    web开发
    Tomcat的安装与环境配置
    java-10异常处理动手动脑
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120053.html
Copyright © 2011-2022 走看看