之后会发现这里会多一个模拟器,之后点击start…打开模拟器
模拟器打开了,下面就可以开始写代码了。
TextView控件,写入文本
添加文本有两种方法,
第一种:
在strings.xml中写入文本,定义一个name名字保存:
自己定义的文本——第一种方法
之后在activity_main.xml中添加
<TextView
android:id=“@+id/tv1”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“@string/myText” />
第二种方法(很重要):
在MainActivity.java中添加
private LinearLayout layout;
TextView textView = new TextView(this);
textView.setText(“用代码,实例化类创建textView——第二种方法”);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
textView.setLayoutParams(params);
layout = (LinearLayout) findViewById(R.id.LinearLayout1);
layout.addView(textView);
上面两种添加文本的方式,下面来看一下如何设置文本样式
可以直接在activity_main.xml中添加,例:
<TextView
android:id=“@+id/tv”
android:layout_width=“match_parent”
<