(Android Learning series) Three, common events for Windows

Source: Internet
Author: User

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

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.