目录:
MainActivity(第一个界面)的编写:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button2); //界面一button的id查找
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//显示编写
//Intent intent =new Intent(MainActivity.this,MainActivitySecond.class);\
//startActivity(intent);
//隐式编写
Intent intent =new Intent("com.example.texttwo.second");
intent.addCategory("com.example.texttwo.mycategory");
startActivity(intent);
}
});
}
}
MainActivitySecond(第二个界面)的编写:-----------只做跳转对比,界面同一相似!
public class MainActivitySecond extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
一界面的控件:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="first"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转第二个界面"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="447dp" />
就是给个text辨别,然后点击button跳转二界面,第二个界面只有text没有button。
AndroidManifest.xml文件的编写:
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> //初始界面的设置
<activity android:name=".MainActivitySecond">
<intent-filter>
<action android:name="com.example.texttwo.second"></action>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.example.texttwo.mycategory"/>
</intent-filter>//这里如果是隐式的配置,显示的话不用写<intent-filter>!
</activity>
</application>