首先,完成一个布局文件,名字就叫做activity_text_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <TextView
android:id="@+id/ttv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a test"
android:textColor="#5500FF"
android:textSize="32sp"
android:padding="10dp"
/> </LinearLayout>

下面来新建一个TestTextViewActivity.java文件

package com.example.test;

import android.graphics.Paint;
import android.os.Bundle;
import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class TestTextViewActivity extends AppCompatActivity { private TextView mtv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
mtv1 = findViewById(R.id.ttv1);
mtv1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); // set strike through style in the text
mtv1.getPaint().setAntiAlias(true); // get rid of the zigzag effect
}
}

在MainActivity.java文件里加入以下代码:

package com.example.test;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private Button mBtnTextView; // define a text view button
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnTextView = findViewById(R.id.btnTextView1); // get the button, it is in activity_main.xml
mBtnTextView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, TestTextViewActivity.class);
startActivity(intent);
}
});
}; }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <Button
android:id="@+id/btnTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TestTextView"
/> </LinearLayout>

注意:在AndroidMainifest.xml里面加入activity

<activity android:name=".TestTextViewActivity"/>

效果图如下:

最新文章

  1. jQuery所支持的css样式
  2. EhCache的配置
  3. bzoj 1537: [POI2005]Aut- The Bus 线段树
  4. 用gulp建立自动工具,完成软件的编译、测试、打包和发布流程
  5. lr中switch的应用
  6. js函数的调用问题
  7. Java 多线程 —— synchronized关键字
  8. Spark工程开发常用函数与方法(Scala语言)
  9. OpenGL第18,19,20讲小结
  10. 周末充电之WPF(四).多窗口之间操作
  11. Common Lisp 编译器IDE环境搭建
  12. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词
  13. shell 调用mysql 存储过程判断真假
  14. HDU 3699 A hard Aoshu Problem (暴力搜索)
  15. Django编写RESTful API(三):基于类的视图
  16. PHP中的 $_SERVER 函数说明详解
  17. 【ShaderToy】画一个球体
  18. Git 教程(二):提交和回退
  19. mybatis_异常
  20. MongodbHelper

热门文章

  1. cas客户端流程详解(源码解析)--单点登录
  2. Python之常用模块学习(一)
  3. static关键字真能提高Bean的优先级吗?答:真能
  4. 六十来行python代码完成一个文件分类器
  5. css导航菜单二级显示的问题
  6. 2020软件测试自学全套教程-基于python自动化软件测试-2020新版软件测试中级程序员学习路线
  7. 牛客练习赛 66B题解
  8. 高效C++:继承和实现
  9. 【揭秘】阿里测试框架,各大CTO良心力荐
  10. 2.pandas的数据结构