---恢复内容开始---
Activity:
<TextView
android:id="@+id/t1"
android:textSize="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="改变颜色"
/>
<Button
android:id="@+id/b1
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="dj1"
android:text="RED" />
<Button
android:id="@+id/b2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="dj2"
android:text="GREEN" />
<Button
android:id="@+id/b3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="dj3"
android:text="YELLOW" />
JAVA:
final TextView tv=(TextView) findViewById(R.id.t1); final Button btn = (Button)findViewById(R.id.b1);
//设置单击事件,
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//单击时改变颜色 下同
tv.setTextColor(android.graphics.Color.RED);
}
});
final Button btn1 = (Button)findViewById(R.id.b2);
btn1.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv.setTextColor(android.graphics.Color.GREEN);
}
});
final Button btn2= (Button)findViewById(R.id.b3);
btn2.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv.setTextColor(android.graphics.Color.YELLOW);
}
});
显示效果:
---恢复内容结束---