Related reading:
Android Development Series Two window activity lifecycle
Android Development Series A button for display time
Sets the window caption event and jumps between the activity.
Create a new item, create a new two activity:mainactivity,titleactivity, and then register in Anroidmanifest.xml titleactivity
Androidmanifest.xml content is as follows
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" com.neil.ad02 ">
<application
android:allowbackup=" true "
android:icon=" @mipmap/ic_launcher "
android:label=" @string/app_name "
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= ". Titleactivity "
android:label=" @string/app_name ">
</activity>
</application>
</manifest>
In the OnCreate method of Mainactivity
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
LOG.D ("OnCreate", "OnCreate method is executed");
Button bt= (button) Findviewbyid (r.id.btturntitle);
Bt.setonclicklistener (New View.onclicklistener () {public
void OnClick (View v) {
startactivity (new Intent ( Mainactivity.this,titleactivity.class));
}
Click button to trigger Titleactivity OnCreate ()->onstart ()->onresume () method
Add a button to the Activity_title.xml and click the button to change the App_name value
Code in the Titleactivity
package com.neil.ad; import android.app.Activity; import android.os.Bundle; Import Andr
Oid.util.Log;
Import Android.view.View;
Import Android.widget.Button;
/** * Created by Neil on//. */public class Titleactivity extends activity{@Override protected void onCreate (Bundle savedinstancestate) {Super.oncre
Ate (savedinstancestate);
Setcontentview (R.layout.activity_title);
Button bt= (button) Findviewbyid (R.id.bttitle);
Bt.setonclicklistener ((View.onclicklistener) this);
Settitle ("window title"); public void Onclick_settitle (view view) {Settitle ("new Window caption"); Settitlecolor ()///Call this method after the window has completely started @Override protected void Onpostcreate (Bundle savedinstancestate) {log.d ("titleactivity", "onpostcreate"); Super.onpostcreate (
Savedinstancestate);
@Override protected void ontitlechanged (charsequence title,int color) {super.ontitlechanged (title,color);
LOG.D ("Titleactivity", "Ontitlechanged_title" +title);
LOG.D ("Titleactivity", "Ontitlechanged_color" +color); }
}
The
is simpler, so don't say more. If you have any questions welcome to my message, small series will promptly reply to everyone!