Android Base TOP2: Single button to change font color

Source: Internet
Author: User

---restore content starts---

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= "Change Color"       />
<button
android:id= "@+id/b1Android: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:

1 FinalTextView tv=(TextView) Findviewbyid (R.ID.T1);2        3         FinalButton BTN =(Button) Findviewbyid (R.ID.B1);4         //set the Click event,5Btn.setonclicklistener (NewView.onclicklistener () {6 @Override7  Public voidOnClick (View v) {8 //TODO auto-generated Method Stub9 //change color when clickedTen Tv.settextcolor (Android.graphics.Color.RED); One } A }); -         FinalButton BTN1 =(Button) Findviewbyid (R.ID.B2); -Btn1.setonclicklistener (NewView.onclicklistener () { the   - @Override -    Public voidOnClick (View v) { -   //TODO auto-generated Method Stub + Tv.settextcolor (Android.graphics.Color.GREEN); -   } +   }); A           FinalButton btn2=(Button) Findviewbyid (r.id.b3); atBtn2.setonclicklistener (NewView.onclicklistener () { -   - @Override -    Public voidOnClick (View v) { -   //TODO auto-generated Method Stub - Tv.settextcolor (Android.graphics.Color.YELLOW); in   } -});

Display effect:





---restore content ends---

Android Base TOP2: Single button to change font color

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.