效果图

效果图1效果图2

res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/mainl1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名:"
            android:textSize="16sp" />
        <EditText
            android:id="@+id/etname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入用户名:"
            android:textSize="14sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/mainl2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/mainl1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密    码:"
            android:textSize="16sp" />
        <EditText
            android:id="@+id/etpasswd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入密码:"
            android:textSize="14sp"
            android:inputType="textPassword" />
    </LinearLayout>

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/mainl2">
        <RadioButton
            android:id="@+id/rbnan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:checked="true" />
        <RadioButton
            android:id="@+id/rbnv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女" />
    </RadioGroup>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:layout_centerInParent="true"
        android:onClick="click" />

</RelativeLayout>

res/values/activity_show.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/showl1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名:"
            android:textSize="20sp" />
        <TextView
            android:id="@+id/tvname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/showl2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/showl1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密    码:"
            android:textSize="20sp" />
        <TextView
            android:id="@+id/tvpasswd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/showl2">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性    别:"
            android:textSize="20sp" />
        <TextView
            android:id="@+id/tvsex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</RelativeLayout>


res/values/MainActivity.java

package cn.gputer.a0319;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity {

    private EditText etname;
    private EditText etpasswd;
    private RadioButton rbnan;
    private RadioButton rbnv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etname = (EditText)findViewById(R.id.etname);
        etpasswd = (EditText)findViewById(R.id.etpasswd);
        rbnan = (RadioButton)findViewById(R.id.rbnan);
        rbnv = (RadioButton)findViewById(R.id.rbnv);

    }

    public void click(View view) {
        String name = etname.getText().toString();
        String passwd = etpasswd.getText().toString();
        String sex = "";
        if (rbnan.isChecked()) {
            sex = "男";
        } else if (rbnv.isChecked()) {
            sex = "女";
        }

        Bundle bundle = new Bundle();
        bundle.putString("name", name);
        bundle.putString("passwd", passwd);
        bundle.putString("sex", sex);

        Intent intent = new Intent(this, ShowActivity.class);
        intent.putExtras(bundle);
        startActivity(intent);
    }

}


res/values/ShowActivity.java

package cn.gputer.a0319;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class ShowActivity extends Activity {
    private TextView tvname;
    private TextView tvpasswd;
    private TextView tvsex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_show);

        tvname = (TextView)findViewById(R.id.tvname);
        tvpasswd = (TextView)findViewById(R.id.tvpasswd);
        tvsex = (TextView)findViewById(R.id.tvsex);

        Intent intent = getIntent();

        Bundle bundle = intent.getExtras();

        tvname.setText(bundle.getString("name"));
        tvpasswd.setText(bundle.getString("passwd"));
        tvsex.setText(bundle.getString("sex"));
    }
}


res/values/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.gputer.a0319">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        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=".ShowActivity"></activity>
    </application>

</manifest>


版权属于:GPUter
本文链接:http://gputer.top/index.php/archives/343/
本站文章采用 "知识共享署名4.0 国际许可协议" 进行许可,请在转载时注明出处及本声明!

最后修改:2020 年 03 月 20 日 08 : 49 PM
如果您觉得不错的话送我一包薯片吧!请赞赏,谢谢您!