Set the window caption event and jump between activity
Create a new project, create a new two activity:mainactivity,titleactivity, and then register it in Anroidmanifest.xml titleactivity
Androidmanifest.xml content is as follows
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "COM.NEIL.AD02"> <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme"> <ActivityAndroid:name=". Mainactivity "> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <ActivityAndroid:name=". Titleactivity "Android:label= "@string/app_name"> </Activity> </Application></Manifest>
In the OnCreate method in Mainactivity
@Overrideprotected voidonCreate (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 (NewView.onclicklistener () { Public voidOnClick (View v) {startactivity (NewIntent (mainactivity. This, Titleactivity.class)); } }); }
Click button to trigger Titleactivity OnCreate ()->onstart ()->onresume () method
Add a button to Activity_title.xml and click the button to change the value of App_name
Code in the Titleactivity
1 Packagecom.neil.ad02;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 ImportAndroid.util.Log;6 ImportAndroid.view.View;7 ImportAndroid.widget.Button;8 9 /**Ten * Created by Neil on 2016/4/30. One */ A Public classTitleactivityextendsactivity{ - - the @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_title); +Button bt=(Button) Findviewbyid (r.id.bttitle); -Bt.setonclicklistener ((View.onclicklistener) This); +Settitle ("window caption"); A } at - Public voidonclick_settitle (view view) - { -Settitle ("new window title"); -Settitlecolor (12345); - } in - //call this method after the window has completely started to @Override + protected voidonpostcreate (Bundle savedinstancestate) { -LOG.D ("Titleactivity", "Onpostcreate"); the Super. Onpostcreate (savedinstancestate); * } $ Panax Notoginseng - @Override the protected voidOntitlechanged (charsequence title,intcolor) + { A Super. ontitlechanged (Title,color); theLOG.D ("Titleactivity", "ontitlechanged_title" +title); +LOG.D ("Titleactivity", "Ontitlechanged_color" +color); - } $ $}
It's easier than that.
(Android Learning series) Three, common events for Windows