<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="60dp"
android:layout_marginRight="20dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手机号码:"
android:textColor="@android:color/black"
android:textSize="30sp" />
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@drawable/text_sharp" />
</LinearLayout>
<Button
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/text_sharp"
android:onClick="one"
android:text="充值"
android:textSize="35sp" />
<TextView
android:id="@+id/tv_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="15dp"
android:layout_marginBottom="200dp"
android:textColor="@android:color/black"
android:textSize="28dp" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<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=".Main2Activity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:layout_marginRight="30dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="您的号码是:"
android:textSize="35sp" />
<TextView
android:id="@+id/tv_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:textSize="35sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="50dp"
android:layout_marginRight="40dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="充值金额:"
android:textSize="35sp" />
<EditText
android:id="@+id/et_money"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="@drawable/text_sharp"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:orientation="horizontal">
<Button
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginLeft="35dp"
android:onClick="two1"
android:text="充值"
android:textSize="32sp" />
<Button
android:layout_width="180dp"
android:layout_height="60dp"
android:layout_marginLeft="35dp"
android:onClick="two2"
android:text="取消充值"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
package com.example.workeight;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Main2Activity extends AppCompatActivity {
private TextView tv_number;
private EditText et_money;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
tv_number = findViewById(R.id.tv_number);
et_money = findViewById(R.id.et_money);
Intent intent = getIntent();
tv_number.setText(intent.getStringExtra("number"));
}
public void two1(View view) {
Intent intent = new Intent();
intent.putExtra("data", et_money.getText().toString().trim());
setResult(2, intent);
finish();
}
public void two2(View view) {
Intent intent = new Intent();
setResult(3, intent);
finish();
}
}