例子2_1
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="59dp"
android:textSize="22sp"
android:id="@+id/textView" />
</RelativeLayout>
strings.xml
<resources>
<string name="app_name">ex2_1</string>
<string name="hello">
\n 荷塘月色
\n 剪一段时光缓缓流淌,
\n 弹一首小荷淡淡的香,
\n 美丽的琴音就落在我身旁。
</string>
</resources>
MainActivity.java
package com.example.yanhsama.example1_1;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView)findViewById(R.id.textView);
txt.setTextColor(Color.BLUE);
}
}
效果显示