1. Knowledge points
1. Master the configuration and use of text display components;
2. Master the inheritance structure of text display components;
3. Master the basic properties and operation methods of text display components.
2. Specific content
Through this inheritance relationship, it is found that it is a subclass of the View class, so the sub-component can use all the properties and methods defined in the View class.
Now we define a TextView component.
<TextView
android:id="@+id/mytext"
android:layout_width="match_parent"—宽度全屏
android:layout_height="wrap_content"—高度包裹
android:text="@string/hello_world" –内容
android:textColor="#A25E87"—字体颜色
android:textSize="25px"—字体 大小
android:password="true"/>--密文显示
<TextView
android:id="@+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#A25E87"
android:textSize="25px"
android:layout_marginLeft="50px"—离左边距离30px
android:textStyle="bold"—字体加粗
android:maxLength="3"/>--最多显示3个字符
<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"
android:background="@drawable/logo">--设置背景图片
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="mytext">
<item name="android:textSize">25px</item>--定义属性和属性值
</style>
</resources>
The above is the style that defines our components. It is generally used when the artist defines the overall style of the component.
<TextView
android:id="@+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#A25E87"
android:layout_marginLeft="50px"
android:textStyle="bold"
android:autoLink="web"
style="@style/mytext"/>--引用样式文件
The properties of the text display component can be set in the layout file, and can also be set through the Activity program.
public class TextViewActivity extends Activity {
private TextView textView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_textview);
this.textView = (TextView) super.findViewById(R.id.mytext);
this.textView.setTextSize(30.0f);//设置字体大小
}
}
3. Course Summary
1. As a text component, the main function of TextView is to display text data;
2. All components can configure attributes directly through a style sheet file. (This is very important when unifying styles across many components).