Android基础TOP2:单机按钮改变字体颜色

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

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:

 1 final TextView tv=(TextView) findViewById(R.id.t1);
 2
 3         final Button btn = (Button)findViewById(R.id.b1);
 4         //设置单击事件,
 5         btn.setOnClickListener(new View.OnClickListener() {
 6 @Override
 7 public void onClick(View v) {
 8 // TODO Auto-generated method stub
 9 //单击时改变颜色 下同
10 tv.setTextColor(android.graphics.Color.RED);
11 }
12 });
13         final Button btn1 = (Button)findViewById(R.id.b2);
14           btn1.setOnClickListener(new View.OnClickListener() {
15
16   @Override
17   public void onClick(View v) {
18   // TODO Auto-generated method stub
19   tv.setTextColor(android.graphics.Color.GREEN);
20   }
21   });
22           final Button btn2= (Button)findViewById(R.id.b3);
23           btn2.setOnClickListener(new View.OnClickListener() {
24
25   @Override
26   public void onClick(View v) {
27   // TODO Auto-generated method stub
28   tv.setTextColor(android.graphics.Color.YELLOW);
29   }
30   });

显示效果:

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

时间: 2024-08-01 15:20:30

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

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

RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width="200dp" android:layout_height="40dp" android:layout_marginLeft="5dp" android:layout_alignParentRight="true" android

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

RadioGroup [html] view plaincopy <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width="200dp" android:layout_height="40dp" android:layout_marginLeft="5dp" android:layout_alignParentRight=&q

android.support.v7.widget.SearchView 修改字体颜色

问题描述:在v4扩展包下的searchView网上通常采用  int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);  TextView textView = (TextView) searchView.findViewById(id);  textView.setTextColor(Color.WHITE);来改变字体颜色,但是在v

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

苦逼的开发者,最终败给了一个任性的UI,系统原生UIAlertController的按纽颜色必须改.于是,开始了不归路.之前的版本是自己用view写的一个仿系统UIActionSheet,动画感觉都挺好,就是毛玻璃背景没有系统的好,由于最低兼容了ios8,所以就抛弃了UIActionSheet,改用UIAlertController. 做法其实很简单,采用runtime机制.对于runtime不了解的,我想还是别看各种介绍文章了,找一个简单的demo多写几遍,就行了. 做法很简单,自己写一个类

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

在TextView中添加文本时有时需要改变一些文本字体的颜色,今天学到了三种方法,拿出来分享一下 1.在layout文件下的配置xml文件中直接设置字体颜色,通过添加android:textcolor=“#FFFFFF”来变化颜色 但这样的效果只能让字体千篇一律的显示一种颜色 2.在activity中通过TextView tv=new TextView(this):实例化一个textview,通过setContentView(tv);将其加载到当前activity,设置要显示的内容String

android 按钮按下时改变字体颜色

1.新建 drawable/button_font_style.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="

Python 改变字体颜色

格式:\033[显示方式;前景色;背景色m 说明:前景色            背景色           颜色---------------------------------------30                40              黑色31                41              红色32                42              绿色33                43              黃色34         

Android给TextView设置多个字体颜色

效果如下: /** * @param textView * @param positions 变色的位置 * @param colors 多个颜色值,数量和positions的数量可以不一致,如果颜色值比位置值少,则是交叉来使用的 * @描述 设置一个textivew显示多种颜色 * @作者 tll * @时间 2016/11/11 10:37 */public static void setMultipleColor(TextView textView, List<Integer> posi

实现对特定内容改变字体颜色的TextView

最近产品中需要一个搜索功能,比如搜索Android,搜索得到的内容中需要对所有的Android进行标红的处理,就自己重写了个textView实现了这个功能.上代码: package com.amuro.custom_text_view; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.text.Spannable; import android.te