Put the finished product drawing first:
The user's registration interface is actually composed of several input boxes (EditText) and TextView. The key point is that the entered phone number and email can be recognized and displayed in the way of hyperlink. After clicking, the corresponding software will be opened. In fact, it's all due to a setting in TextView:
android:autoLink="all"
This code can automatically identify whether the displayed data is email or phone number and display it in the way of hyperlink, which can be said to be very brutal. The implementation of registration window is as follows:
Two windows are used, one is registration window and the other is to display registration information. First, look at the code of activity_register.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/back" android:orientation="vertical" android:padding="15dp" tools:context="com.example.administrator.login.RegisterActivity" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name" android:textSize="25dp" /> <EditText android:id="@+id/edt_name" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sex" android:textSize="25dp" /> <EditText android:id="@+id/edt_sex" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/age" android:textSize="25dp" /> <EditText android:id="@+id/edt_age" android:numeric="decimal" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/phone" android:textSize="25dp" /> <EditText android:id="@+id/edt_phone" android:phoneNumber="true" android:layout_width="200dp" android:layout_height="wrap_content" android:autoLink="all"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/email" android:textSize="25dp" /> <EditText android:id="@+id/edt_eamil" android:layout_width="230dp" android:layout_height="wrap_content" android:autoLink="all" android:singleLine="true"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <Button android:id="@+id/btn_register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register"/> <Button android:id="@+id/btn_canceltwo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cancel"/> </LinearLayout> </LinearLayout>
The RegisterActivity code is as follows:
package com.example.administrator.login; import android.app.Activity; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class RegisterActivity extends Activity { private EditText edtName; private EditText edtSex; private EditText edtAge; private EditText edtPhone; private EditText edtEmail; private Button btnRegister; private Button btnCanseltwo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); Intent intent = getIntent(); edtName = (EditText) findViewById(R.id.edt_name); edtSex=(EditText) findViewById(R.id.edt_sex); edtAge=(EditText)findViewById(R.id.edt_age); edtPhone=(EditText)findViewById(R.id.edt_phone); edtEmail=(EditText)findViewById(R.id.edt_eamil); btnRegister=(Button)findViewById(R.id.btn_register); btnCanseltwo=(Button)findViewById(R.id.btn_canceltwo); btnCanseltwo.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { finish(); } }); btnRegister.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ String name = edtName.getText().toString(); String sex = edtSex.getText().toString(); String phone = edtPhone.getText().toString(); String email = edtEmail.getText().toString(); String age = edtAge.getText().toString(); if(name.equals("")||sex.equals("")||phone.equals("")||age.equals("")||email.equals("")){ Toast.makeText(RegisterActivity.this,"Please confirm that the information is not empty", Toast.LENGTH_SHORT).show(); }else{ Intent intent = new Intent(RegisterActivity.this,RegisterTwo.class); Bundle bundle = new Bundle(); bundle.putString("name",name); bundle.putString("sex",sex); bundle.putString("phone",phone); bundle.putString("email",email); bundle.putString("age",age); intent.putExtras(bundle); startActivity(intent); } } }); } }
The code of activity? Register? Two.xml is as follows:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/back" android:gravity="center" android:orientation="vertical" tools:context="com.example.administrator.login.RegisterTwo"> <TextView android:id="@+id/tv_register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:autoLink="all" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical"> <Button android:id="@+id/btn_re" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/reture"/> </LinearLayout> </LinearLayout>
The RegisterTwo code is as follows:
package com.example.administrator.login; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class RegisterTwo extends Activity { private TextView tvRegister; // private Button btnRe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register_two); // btnRe.findViewById(R.id.btn_re); Intent intent = getIntent(); tvRegister = (TextView) findViewById(R.id.tv_register); if(intent!=null){ Bundle data = intent.getExtras(); String name = data.getString("name"); String age = data.getString("age"); String phone = data.getString("phone"); String sex = data.getString("sex"); String email =data.getString("email"); tvRegister.setText("Full name:" + name + "\n Gender:" + sex + "\n Age:" + age + "\n Telephone:" + phone + "\n Mailbox:" + email); } /** btnRe.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { Intent intent = new Intent(RegisterTwo.this,MainActivity.class); startActivity(intent); } });*/ } }