欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)注冊頁面(攜帶數(shù)據(jù)包跳轉(zhuǎn))

 更新時間:2022年04月23日 16:29:43   作者:doubleview  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)注冊頁面,點(diǎn)擊注冊按鈕跳轉(zhuǎn)到另一個頁面并顯示輸入信息,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

安卓學(xué)習(xí):實(shí)現(xiàn)注冊頁面輸入數(shù)據(jù),點(diǎn)擊注冊按鈕跳轉(zhuǎn)到另一個頁面并顯示輸入信息

效果:

實(shí)現(xiàn)

1.創(chuàng)建安卓文件

2.創(chuàng)建注冊界面,勾選為啟動頁

3.編寫代碼

啟動界面activity_register11.xml

<?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:background="@drawable/bk024"
? ? android:gravity="center"
? ? android:padding="15sp"
? ? android:orientation="vertical"
? ? tools:context=".register11">

? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvName"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/name"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtName"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvSex"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/sex"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtSex"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvAge"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/age"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtAge"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvPhone"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/phone"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtPhone"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvEmail"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/email"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtEmail"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvHomepage"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="@string/homepage"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtHomepage"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center_horizontal">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/tvRemark"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:textColor="#FFFF00"
? ? ? ? ? ? android:text="@string/remark"
? ? ? ? ? ? android:textSize="25sp"/>
? ? ? ? <EditText
? ? ? ? ? ? android:id="@+id/edtRemark"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:ems="12"
? ? ? ? ? ? android:singleLine="true"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:gravity="center_horizontal"
? ? ? ? android:orientation="horizontal">

? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/btnRegister"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:paddingLeft="30dp"
? ? ? ? ? ? android:paddingRight="30dp"
? ? ? ? ? ? android:background="@color/danlv"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:text="@string/register"
? ? ? ? ? ? android:layout_marginRight="10dp"
? ? ? ? ? ? android:textSize="20sp"/>

? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/btnCancel"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:paddingLeft="30dp"
? ? ? ? ? ? android:paddingRight="30dp"
? ? ? ? ? ? android:background="@color/danlv"
? ? ? ? ? ? android:text="@string/cancel"
? ? ? ? ? ? android:textSize="20sp"
? ? ? ? ? ? android:textColor="#ffffff"/>
? ? </LinearLayout>
</LinearLayout>

register11.java

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

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

public class register11 extends AppCompatActivity {
? ? private EditText edtName;
? ? private EditText edtSex;
? ? private EditText edtAge;
? ? private EditText edtPhone;
? ? private EditText edtEmail;
? ? private EditText edtHomepage;
? ? private EditText edtRemark;
? ? private Button btnRegister;
? ? private Button btnCancel;

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_register11);
? ? ? ? //活動欄圖標(biāo)
? ? ? ? ActionBar actionBar = getSupportActionBar();
? ? ? ? actionBar.setDisplayShowHomeEnabled(true);
? ? ? ? actionBar.setDisplayUseLogoEnabled(true);
? ? ? ? actionBar.setLogo(R.mipmap.icon);
? ? ? ? //獲取控件實(shí)例
? ? ? ? edtName = findViewById(R.id.edtName);
? ? ? ? edtSex = findViewById(R.id.edtSex);
? ? ? ? edtAge = findViewById(R.id.edtAge);
? ? ? ? edtPhone = findViewById(R.id.edtPhone);
? ? ? ? edtEmail = findViewById(R.id.edtEmail);
? ? ? ? edtHomepage = findViewById(R.id.edtHomepage);
? ? ? ? edtRemark = findViewById(R.id.edtRemark);
? ? ? ? btnRegister = findViewById(R.id.btnRegister);
? ? ? ? btnCancel = findViewById(R.id.btnCancel);
? ? ? ? //給注冊按鈕注冊監(jiān)聽器
? ? ? ? btnRegister.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? //保存用戶輸入數(shù)據(jù)
? ? ? ? ? ? ? ? String strName=edtName.getText().toString().trim();//trim()去除用戶在前面輸入的空格
? ? ? ? ? ? ? ? String strSex=edtSex.getText().toString().trim();
? ? ? ? ? ? ? ? String strAge=edtAge.getText().toString().trim();//trim()去除用戶在前面輸入的空格
? ? ? ? ? ? ? ? String strPhone=edtPhone.getText().toString().trim();//trim()去除用戶在前面輸入的空格
? ? ? ? ? ? ? ? String strEmail=edtEmail.getText().toString().trim();
? ? ? ? ? ? ? ? String strHomepage=edtHomepage.getText().toString().trim();//trim()去除用戶在前面輸入的空格
? ? ? ? ? ? ? ? String strRemark=edtRemark.getText().toString().trim();

? ? ? ? ? ? ? ? //利用吐司提示用戶注冊情況
? ? ? ? ? ? ? ? Toast.makeText(register11.this, "注冊成功", Toast.LENGTH_SHORT).show();//LENGTH_SHORT表示登錄時間長度
? ? ? ? ? ? ? ? //創(chuàng)建顯示意圖
? ? ? ? ? ? ? ? Intent intent = new Intent(register11.this, MainActivity.class);
? ? ? ? ? ? ? ? //創(chuàng)建數(shù)據(jù)包封裝數(shù)據(jù)(封裝)
? ? ? ? ? ? ? ? Bundle date = new Bundle();
? ? ? ? ? ? ? ? date.putString("name", strName);
? ? ? ? ? ? ? ? date.putString("sex", strSex);
? ? ? ? ? ? ? ? date.putString("age", strAge);
? ? ? ? ? ? ? ? date.putString("phone", strPhone);
? ? ? ? ? ? ? ? date.putString("email", strEmail);
? ? ? ? ? ? ? ? date.putString("homepage", strHomepage);
? ? ? ? ? ? ? ? date.putString("remark", strRemark);
? ? ? ? ? ? ? ? //通過意圖攜帶數(shù)據(jù)包
? ? ? ? ? ? ? ? intent.putExtras(date);
? ? ? ? ? ? ? ? //按照意圖啟動目標(biāo)組件
? ? ? ? ? ? ? ? startActivity(intent);

? ? ? ? ? ? }
? ? ? ? });
? ? ? ? btnCancel.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? //關(guān)閉窗口
? ? ? ? ? ? ? ? finish();
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

activity_main.xml

<?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:gravity="center"
android:background="@drawable/bk028"
tools:context=".MainActivity">

<TextView
? ? android:id="@+id/tvMessage"
? ? android:layout_width="wrap_content"
? ? android:layout_height="wrap_content"
? ? android:text=" "
? ? android:textSize="25dp"
? ? android:textColor="#ff2233"
? ? />
</LinearLayout>

ActivityMain.java

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
? ? protected TextView tvMessage;

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //通過資源標(biāo)識符獲取控件實(shí)例
? ? ? ? tvMessage = findViewById(R.id.tvMessage);
? ? ? ? //獲取意圖
? ? ? ? Intent intent = getIntent();
? ? ? ? //判斷意圖是否為空
? ? ? ? if (intent != null) {
? ? ? ? ? ? //獲取意圖攜帶數(shù)據(jù)包(封裝)
? ? ? ? ? ? Bundle date = intent.getExtras();
? ? ? ? ? ? String name = date.getString("name");
? ? ? ? ? ? String sex = date.getString("sex");
? ? ? ? ? ? String age = date.getString("age");
? ? ? ? ? ? String phone = date.getString("phone");
? ? ? ? ? ? String email = date.getString("email");
? ? ? ? ? ? String homepage = date.getString("homepage");
? ? ? ? ? ? String remark = date.getString("remark");
? ? ? ? ? ? //拼接用戶信息
? ? ? ? ? ? String message = "注冊成功!\n姓名:" + name + "\n性別:" + sex + "\n年齡:" + age + "\n電話:" + phone + "\n郵箱:" + email + "\n主頁:" + homepage + "\n備注:" + remark;
? ? ? ? ? ? //設(shè)置標(biāo)簽屬性,顯示用戶信息
? ? ? ? ? ? tvMessage.setText(message);
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論