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

  • 相关阅读:
    数据库30条规范
    数据库索引原理
    HashMap的实现原理
    Google 和 Baidu 常用的搜索技巧
    Arrays工具类十大常用方法
    fastjson将json格式null转化空串
    SolrCloud的介绍
    网页背景图片自适应浏览器大小
    addlinkedserver
    常用
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120054.html
Copyright © 2011-2022 走看看