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

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. Codeforces Round #260 (Div. 2) D

    D. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. RSA的共模攻击

    实验吧题目:http://www.shiyanbar.com/ctf/1834 参考:http://hebin.me/2017/09/07/%e8%a5%bf%e6%99%aectf-strength ...

  3. node.js 核心http模块,起一个服务器,返回一个页面

    let http=require("http"); //引入核心http模块 let fs=require("fs"); let mime={ '.js':'a ...

  4. ECMAScript 6 入门学习笔记(零)——开始

    所有es6笔记都是我自己提出来的一些点,没有很详细的例子什么的,这个链接就是我看的教程,有需要的可以看看.(http://es6.ruanyifeng.com/#docs/intro) 1.ECMAS ...

  5. __weak与__block区别分析

    API Reference对__block变量修饰符有如下几处解释: //A powerful feature of blocks is that they can modify variables ...

  6. 辛星浅谈mysql中的数据碎片以及引擎为MyISAM下的操作

    对于mysql中的数据碎片,事实上和我们删除数据是息息相关的,删除数据的时候必定会在数据文件里造成不连续的空白空间,对于少量的数据的删除,并不会产生多少的空白空间.假设在一段时间内的大量的删除操作,会 ...

  7. mysql 存储引擎的选择你会吗?

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXExMzU1NTQxNDQ4/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  8. FFmpeg滤镜使用指南

    文件夹 1. FFmpeg滤镜文档 2. 演示样例   2.1 缩放   2.2 视频加速   2.3 滤镜图,链和滤镜关系   2.4 多个输入覆盖同一个2x2 网格   2.5 转义字符   2. ...

  9. uboot的GPIO驱动分析--基于全志的A10芯片【转】

    本文转载自:http://blog.csdn.net/lw2011cg/article/details/68954707 uboot的GPIO驱动分析--基于全志的A10芯片 转载至:http://b ...

  10. 乐视云监控数据存放到influxdb中

    3.9     监控.告警系统 监控报警我们分PaaS平台和业务应用两大类. PaaS平台主要聚焦在基础设施和LeEngine的各个服务组件的监控报警(比如主机CPU,内存,IO,磁盘空间,LeEng ...