#ff00ff00res/drawable/mail.xml
当前位置:   article > 正文

更改TextView文字颜色——引用color.xml中的颜色常数

c# android:textcolor

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);
    }
}

转载于:https://www.cnblogs.com/AlexCheng/archive/2011/03/24/2120053.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/293728
推荐阅读
相关标签
  

闽ICP备14008679号