按钮改变文字大小颜色
来源:互联网 发布:炸群软件 编辑:程序博客网 时间:2024/05/30 04:47
实现点击按钮改变文字颜色
1、文件结构
2、layout 代码
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.lumeng.myapplication.MainActivity"> <LinearLayout android:layout_width="fill_parent" android:layout_height="200dp" android:layout_gravity="center" android:orientation="horizontal"> <TextView android:id="@+id/testview_id" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="@string/HW" android:textSize="30dp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="200dp" android:layout_gravity="center" android:orientation="horizontal"> <Button android:id="@+id/bt_big" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="@string/CB" android:textSize="40dp"/> </LinearLayout></RelativeLayout>
3、MainActivity.java程序
package com.example.lumeng.myapplication;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button bt_changebig; private TextView tx_view; private int size=50; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tx_view = (TextView) findViewById(R.id.testview_id); bt_changebig = (Button) findViewById(R.id.bt_big); bt_changebig.setOnClickListener(this); } @Override public void onClick(View view) { int id = view.getId(); switch (id) { case R.id.bt_big: changebig(); break; default: break; } } public void changebig(){ tx_view.setTextColor(getColor(R.color.green)); tx_view.setTextSize(size); }}
4、效果显示
前
后
本人郑重声明,本博客所著文章、图片版权归权利人持有,本博只做学习交流分享所用,不做任何商业用途。访问者可將本博提供的內容或服务用于个人学习、研究或欣赏,不得用于商业使用。同時,访问者应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人的合法权利;如果用于商业用途,须征得相关权利人的书面授权。若以上文章、图片的原作者不愿意在此展示內容,请及时通知在下,將及时予以刪除。
阅读全文
0 0
- 按钮改变文字大小颜色
- WebView改变网页文字大小、颜色,背景颜色
- WebView改变网页文字大小、颜色,背景颜色
- iOS_UIWebView背景颜色、文字颜色、文字大小的改变
- 改变文字大小
- 自动改变文字大小和颜色的javascript效果
- android 改变spinner的文字大小 颜色的思路
- SpannableString设置AndroidTextView改变颜色,文字大小,图文混排等等
- MFC中改变编辑框文字大小、颜色的方法
- iOS开发绘制三角形和添加文字改变文字大小颜色
- 按钮点击改变文字颜色
- 点击按钮字体颜色改变
- Qt 程序改变文字大小
- UIWebView实时改变文字大小
- 自定义导航条 文字大小颜色等 按钮大小图标等 背景色
- 点击按钮改变div的颜色
- android 按钮按下时改变字体颜色
- android 中改变按钮按下时的颜色
- 接口与实现:实验2
- iPhone X(10)屏幕分辨率与适配
- Activemq 的topic总结
- poj 3164 通信网络 最小树状图
- SpringBoot项目导入外部服务器
- 按钮改变文字大小颜色
- HHUOJ_1349: 分割排序
- string公共函数
- Java经典算法例子大全
- Python中unittest框架写测试用例
- 漫画:什么是MD5算法
- iOS 屏幕尺寸、逻辑分辨率、物理分辨率之间的相互关系
- python学习笔记 第一章
- C++ IO流