Android studio TextView的 用法详情

TextView

简介 :向用户显示文本,并可选择允许他们编辑文本。TextView是一个完整的文本编辑器,但是基类为不允许编辑;其子类EditText允许文本编辑。

点击参考属性

先上代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
  <TextView
      android:id="@+id/textView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="我是测试文字"
      android:textSize="30sp"
      />

</LinearLayout>

布局设置一个控件id,根据id,我们可以在Java代码中通过findViewById()的方法获取到该对象,然后进行相关属性的设置 (所有的方法都有id)

public class MainActivity extends AppCompatActivity {

    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化 通过自己定义的id 获取到id所在的控件,对其进行修改
        text=findViewById(R.id.textView);
        //把字体换成登录页面
        text.setText("登录页面");
        //给字体修改个颜色 Color.RED 这种写法是取系统默认存在的颜色值
        text.setTextColor(Color.RED);
        //修改字体的大小
        text.setTextSize(50);
    }
}
  • 再次运行到手机上,效果图
    在这里插入图片描述
  • text.setTextColor() 也可以使用自定义的
text.setTextColor(getResources().getColor(R.color.black));

这个时候你就可以用自定义的任何颜色值了(通过name ,找color对应的颜色值的)
在这里插入图片描述

  • 以上是平常最常用的,当然也有更多的属性,这里没有一一列举,感兴趣的话可以自己试试,如有疑问欢迎留言谈论
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AaVictory.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值