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

  • 相关阅读:
    java中不常见的keyword:strictfp,transient
    D3DXMatrixMultiply 函数
    expect
    char* 和char[]的差别
    下载安装tomcat6.0
    Eclipse或SVN—怎样在Eclipse中安装SVNclient插件
    sharepoint 訪问缩略图
    斜率优化专题1——bzoj 1597 [Usaco2008 Mar] 土地购买 题解
    phpmywind教程:关于日期函数调用整理
    linux服务之smtp
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120054.html
Copyright © 2011-2022 走看看