The background image itself is replaced or changed to a background color.
Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.text.TextUtils;ImportAndroid.view.View;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateEditText Et_boyname; PrivateEditText Et_girlname; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Et_boyname= (EditText) This. Findviewbyid (R.id.et_boyname); Et_girlname= (EditText) This. Findviewbyid (R.id.et_girlname); } Public voidBtn_calc (view view) {String Boyname=Et_boyname.gettext (). toString (); String Girlname=Et_girlname.gettext (). toString (); if(Textutils.isempty (boyname)) {Toast.maketext ( This, "The boy's name cannot be empty", 0). Show (); Et_boyname.setfocusableintouchmode (true); Et_boyname.requestfocus (); Et_boyname.requestfocusfromtouch (); return; } if(Textutils.isempty (girlname)) {Toast.maketext ( This, "The girl name cannot be empty", 0). Show (); Et_girlname.setfocusableintouchmode (true); Et_girlname.requestfocus (); Et_girlname.requestfocusfromtouch (); return; } Intent Intent=NewIntent ( This, Secondactivity.class); Intent.putextra ("Boyname", Boyname); Intent.putextra ("Girlname", Girlname); StartActivity (Intent); }}
mport android.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classSecondactivityextendsActivity {PrivateTextView Tv_result; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_second); Tv_result= (TextView) This. Findviewbyid (R.id.tv_result); Intent Intent=getintent (); if(Intent! =NULL) {String boyname= Intent.getstringextra ("Boyname"); String Girlname= Intent.getstringextra ("Girlname"); intHashcode = Boyname.hashcode () +Girlname.hashcode (); Random Random=NewRandom (hashcode); intran = random.nextint (100); Tv_result.settext (Boyname+ "and" + Girlname + "of the Marriage value:" +ran); } }}
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical"Tools:context=". Mainactivity "android:gravity= "Center_vertical"Android:background= "@drawable/aiqing" > <EditText Android:id= "@+id/et_boyname"Android:layout_width= "Match_parent"Android:layout_height= "40DP"Android:hint= "Please enter the boy's name"/> <EditText android:layout_margintop= "30DP"Android:id= "@+id/et_girlname"Android:layout_width= "Match_parent"Android:layout_height= "40DP"Android:hint= "Please enter girl name"/> <Button android:layout_margintop= "30DP"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"android:gravity= "Center_vertical|center_horizontal"Android:onclick= "Btn_calc"Android:text= "Start Calculating marriage"/></linearlayout>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "@drawable/jieguo"android:orientation= "Vertical"Tools:context=". Secondactivity "> <TextView android:gravity= "Center_vertical"Android:id= "@+id/tv_result"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:textcolor= "#ff0000"android:textsize= "18SP"Android:text= "Marriage value"/></linearlayout>
Run:
Calculate the value of a two-person marriage based on a male or female name