zoukankan      html  css  js  c++  java
  • 更改TextView背景色——编码定义颜色

    res/values/color.xml
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="red">#ffff0000</color>
    </resources>
    src/EX03_03.java
    package gphone.ex03_03;
    
    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.widget.TextView;
    public class EX03_03 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 color=resources.getColor(R.color.red);
            TextView tv=(TextView)this.findViewById(R.id.text);
            tv.setBackgroundColor(color);
        }
    }

    或颜色在编码时定义使用系统定义颜色:

    package gphone.ex03_03;
    
    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.widget.TextView;
    public class EX03_03 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 color=resources.getColor(R.color.red);*/
            TextView tv=(TextView)this.findViewById(R.id.text);
            
            tv.setBackgroundColor(android.graphics.Color.RED);
        }
    }

    image

  • 相关阅读:
    mahout协同过滤算法
    如何实现团队的自组织管理
    Trail: JDBC(TM) Database Access(3)
    JavaEE5 Tutorial_JavaBean,JSTL
    JavaEE5 Tutorial_Jsp,EL
    JavaEE5 Tutorial_Servlet
    J2SE7规范_2013.2_类
    J2SE7规范_2013.2_类型_命名
    Trail: JDBC(TM) Database Access(2)
    Trail: JDBC(TM) Database Access(1)
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120054.html
Copyright © 2011-2022 走看看