---恢复内容开始---

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

显示效果:

---恢复内容结束---

Android基础TOP2:单机按钮改变字体颜色的更多相关文章

  1. Android RadioGroup的RadioButton 选择改变字体颜色和背景颜色

    RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...

  2. RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色

    RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...

  3. UIAlertController 简单修改title以及按钮的字体颜色

    苦逼的开发者,最终败给了一个任性的UI,系统原生UIAlertController的按纽颜色必须改.于是,开始了不归路.之前的版本是自己用view写的一个仿系统UIActionSheet,动画感觉都挺 ...

  4. markdown改变字体颜色和大小

    markdown中改变字体颜色与大小方法同html 先看例子 <font face="黑体">我是黑体字</font> 我是黑体字 <font fac ...

  5. 色彩缤纷的python(改变字体颜色及样式不完全版)

    色彩缤纷的python(改变字体颜色及样式) *补上昨天随笔中提到的改变字体颜色样式的方法,昨日随笔https://www.cnblogs.com/Du704/p/11265958.html 在项目过 ...

  6. 色彩缤纷的Python(改变字体颜色及样式)

    色彩缤纷的python(改变字体颜色及样式) 在项目过程中,我们常常会因为输出信息的颜色与样式过于单调以至于让人在视觉上感到很杂乱,所以看下文: 在Linux终端中,使用转义序列来进行如上所述的显示, ...

  7. Android 改变字体颜色的三种方法

    在TextView中添加文本时有时需要改变一些文本字体的颜色,今天学到了三种方法,拿出来分享一下     1.在layout文件下的配置xml文件中直接设置字体颜色,通过添加android:textc ...

  8. Android沉浸式状态栏背景色以及字体颜色的修改

    在activity中设置透明状态栏 的思路:    1.让activity的布局全屏 此时布局会和状态栏重叠        2.让布局最上方预留出和状态栏高度一样的高度,将状态栏的背景色设置为透明 效 ...

  9. 关于richtextbox改变字体颜色,加下划线

    参考了三份有用的资料: 1.关于richtextbox设置字体颜色的问题 http://biancheng.dnbcw.net/c/180381.html 2.C#Winform使用扩展方法自定义富文 ...

随机推荐

  1. MVC系统学习1—MVC执行流程

    用MVC来做开发也有一段时间了,但是感觉一直没入门,就徘徊在似懂非懂的层次,和去年刚毕业学习WebForm时一样,当时通过张子阳老兄的几篇文章,明白了请求处理流程,页面生命周期才真正明白了WebFor ...

  2. KMP超强模板贴一份

    )== ) {         );         next[]=; ;         ;i<=n;i++) {             ]!=str[i]) j=next[j];      ...

  3. ACM数论常用知识完全解读

    此版本纯属扯淡....... 一个一个来起.

  4. bzoj 1664 (贪心)

    [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 487  Solved: ...

  5. codevs1005 生日礼物

    题目描述 Description 9月12日是小松的朋友小寒的生日.小松知道小寒特别喜欢蝴蝶,所以决定折蝴蝶作为给小寒的生日礼物.他来到了PK大学最大的一家地下超市,在超市里,小松找到了n种可以用来折 ...

  6. xcode5下取消ARC

    打开你的工程,点击目录的工程文件,最顶端蓝色的,然后选择project下你的工程,还是蓝色那项,然后build Settings,然后往下拉,在Apple LLVM 5.0 - Language - ...

  7. [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学

    Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...

  8. scp: useful commands

    Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_userna ...

  9. UVA - 10324 Zeros and Ones

    Description Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are ...

  10. 自己定义 View 基础和原理

    课程背景: 在 Android 提供的系统控件不能满足需求的情况下,往往须要自己开发自己定义 View 来满足需求,可是该怎样下手呢.本课程将带你进入自己定义 View 的开发过程,来了解它的一些原理 ...