TextView文本框实验

原创  灵思致远  2018-05-16


1. 实验内容简介

(1)TextView定义了文本框操作的基本方法,它是一个不可编辑的文本框,往往用来在屏幕中显示静态字符串。

通过以下方法对文本框进行设置,如下:

        setText("Look,I have  been changed!");//设置文本内容

        setTextColor(Color.rgb(0,255,0));//设置文本颜色

        setTextSize(20);//设置文本大小,以像素为单位

(2)文本框使用步骤:

步骤1:声明变量

步骤2:通过FindViewById关联或绑定

步骤3:监听用户输入动作

(3)常用快捷键的使用方法

ctrl+shift+f 自动排版对齐

ctrl+shift+o  自动导入库

alt+/   自动补齐代码

 

2. UI界面布局


对应的大纲:



对应的属性框:



3. 代码编写和调试

(1)MainActivity.java

public class MainActivity extends Activity {

    TextView  mtv;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mtv=(TextView)this.findViewById(R.id.textView1);

        mtv.setText("Look,I have  been changed!");

        mtv.setTextColor(Color.rgb(0,255,0));

        mtv.setTextSize(20);

       

    }

}

(2)activity_main.xml

<RelativeLayoutxmlns: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"

   tools:context="${relativePackage}.${activityClass}" >

 

    <TextView

       android:id="@+id/textView1"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"

       android:layout_centerVertical="true"

       android:text="This is a demo"

       android:textColor="#561b44"

       android:textSize="20sp" />

 </RelativeLayout>

说明:RelativeLayout标签包含一个TextView的子标签,这个标签定义了一个TextView的对象。程序会根据这个标签的定义加载一个文本框。android:text属性表示TextView组件所显示的内容



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值