Manually create an empty activity yourself, create and load layouts, effects: Top-aligned buttons appear in the interface
Use toast in an activity: respond to a click button
Use menu in an activity, Effect: Menu appears in the interface, and clicking the corresponding option will respond
Demo:
Firstactivity.java
Packagecom.example.hs769.activitytest;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.Toast; Public classFirstactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.first_layout); Button button1=(Button) Findviewbyid (r.id.button_1); Button1.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {toast.maketext (firstactivity. This, "You clicked Button 1", Toast.length_short). Show (); } }); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main,menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {Switch(Item.getitemid ()) { CaseR.id.add_item:toast.maketext ( This, "you click Add", Toast.length_short). Show (); Break; CaseR.id.remove_item:toast.maketext ( This, "you click Remove", Toast.length_short). Show (); Break; default: } return true; }}
Two methods were rewritten
First_layout.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical "android:layout_width=" match_parent " android:layout _height= "Match_parent" > <button android:id= "@+id/button_1" android: Layout_width= "Match_parent" android:layout_height= "Wrap_content" android:text = "Button1" /></linearlayout>
Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><menu xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@+id/add_item" android:title= "Add"/> < Item Android:id= "@+id/remove_item" android:title= "Remove"/></menu>
Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.hs769.activitytest" > <Application Android:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme" > <activity android:name= ". Firstactivity "Android:label= "This is firstactivity" > <intent-filter> <action android:name= "Android.intent.actio N.main "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filte R> </activity> </application></manifest>
Android Development Learning--day4