Android学习--Hello World

Hello World的显示一共两种方式:

1.Android的推荐的通过XML界面设计的:在res/layout目录下包含一个main.xml的文件。它下面都过定义:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
TextView组件,定义了一个可以显示的组件,其中android:text=“@string/hello_world”,指出了组件显示内容的是res/values目录下string.xml下有一个name 为“hello_world”的字符串。


其中string.xml中:


显示其中的内容。

2.第二种方式是通过在MainActivity中直接引入控件并让其显示:

首先,引入TextView控件: import android.widget.TextView;

其次,通过实例化TextView: TextView textView=new TextView(this);

最后,通过setContentView()将控件加入到界面: setContentView(textView);

详细代码如下:

Android学习--Hello World_第1张图片

你可能感兴趣的:(android,textview)