activity 的跳转
在app文件夹上右键新建空的activity ,名称为DisplayMessageActivity,
修改layout文件夹下activity_display_message.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/ttv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="edit_message" android:textColor="#5500FF" android:textSize="32sp" android:padding="10dp" /> <TextView android:id="@+id/ttv2" android:layout_width="355dp" android:layout_height="wrap_content" android:maxLines="1" android:ellipsize="end" android:padding="10dp" android:text="what are you going to do" android:textColor="#00FF55" android:textSize="32sp" /> <TextView android:id="@+id/ttv3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="More Info" android:textSize="32sp" android:padding="10dp" /> </LinearLayout>
修改activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/btnTextView1" android:layout_width="223dp" android:layout_height="69dp" android:text="TestTextView" /> </LinearLayout>
修改MainActivity.java
package com.example.myapplication; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button mBtnTextView; // define a text view button @Override protected void onCreate(Bundle x) { super.onCreate(x); setContentView(R.layout.activity_main); mBtnTextView = findViewById(R.id.btnTextView1); // get the button, it is in activity_main.xml mBtnTextView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent intent = new Intent(MainActivity.this, DisplayMessageActivity.class); startActivity(intent); } }); }; }
修改DisplayMessageActivity.java
package com.example.myapplication; import android.graphics.Paint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class DisplayMessageActivity extends AppCompatActivity { private TextView mtv1; @Override protected void onCreate(Bundle x) { super.onCreate(x); setContentView(R.layout.activity_display_message); mtv1 = findViewById(R.id.ttv1); mtv1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); // set strike through style mtv1.getPaint().setAntiAlias(true); // get rid of the zigzag effect } }
修改AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" > <!-- The meta-data tag is required if you support API level 15 and lower --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /> </activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
点击运行!