您的位置:首页 > 其它

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

2011-03-24 11:07 661 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐