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);
        }
    }
  • 相关阅读:
    团队作业第四次
    团队作业第三次
    团队作业第二次(2)
    团队作业第二次(1)
    团队作业1
    Pillow库
    pyautogui库
    Python文件读取与异常
    元注解
    Java注解
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120053.html
Copyright © 2011-2022 走看看