Android Development Series Three windows of the common event _android

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.