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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值