您的位置:首页 > 其它

安卓修改背景色和文字的颜色

2013-08-27 09:22 295 查看
1,可以在color.xml中先定义颜色例如下面

<?xml version="1.0" encoding="utf-8"?>

<resources>

<drawable name="c1">#0ffff0</drawable>

<drawable name="c2">#00FFFF</drawable>

<drawable name="translucent_background">#7F000000</drawable>

</resources>

再在

main.xml里面添加背景的颜色android:background="@drawable/c1"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/c1"
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="121dp"
        android:layout_toLeftOf="@+id/editText1"
        android:text="账号"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignParentRight="true"
        android:layout_marginRight="40dp"
        android:ems="10" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="28dp"
        android:text="密码"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/editText1"
        android:ems="10"
        android:inputType="textPassword" >

        <requestFocus />
    </EditText>

</RelativeLayout>


也可以在oncreat()里面修改颜色textview = (TextView)findViewById(R.id.textView1);textview.setTextColor(Color.RED);



Resources resources = getBaseContext().getResources();

Drawable HippoDrawable = resources.getDrawable(R.drawable.c2);

textview1.setBackgroundDrawable(HippoDrawable);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: