Android實(shí)現(xiàn)注冊頁面
本文用Android studio制作了簡單的手機(jī)QQ登錄界面,其中界面的布局采用了線性布局、表格布局(不固定布局方法),并給控件綁定監(jiān)聽器,當(dāng)用戶點(diǎn)擊登陸按鈕時,把用戶所填寫的注冊內(nèi)容顯示在“注冊”按鈕下面的文本框內(nèi)。
實(shí)現(xiàn)的效果圖:

代碼:
package com.example.project309;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
?
public class MainActivity extends AppCompatActivity {
? ? EditText name;
? ? EditText password;
? ? RadioButton man;
? ? RadioButton woman;
? ? Button ?show;
? ? TextView shower;
? ? CheckBox auto;
? ? CheckBox remember;
? ? String ?result="";
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? name = findViewById(R.id.name);
? ? ? ? password = findViewById(R.id.password);
? ? ? ? man = findViewById(R.id.man);
? ? ? ? woman = findViewById(R.id.woman);
? ? ? ? show = findViewById(R.id.show);
? ? ? ? shower = findViewById(R.id.shower);
? ? ? ? auto = findViewById(R.id.auto);
? ? ? ? remember = findViewById(R.id.remember);
? ? ? ? show.setOnClickListener(this::onClick);
? ? }
? ? public void onClick(View v){
? ? ? ? String user = name.getText().toString();
? ? ? ? result +="姓名:"+user+"\n";
? ? ? ? String pass =password.getText().toString();
? ? ? ? result +="密碼:"+pass+"\n";
? ? ? ? if(man.isChecked()){
? ? ? ? ? ? result+="性別:"+man.getText().toString()+"\n"+"設(shè)置:";
? ? ? ? }
? ? ? ? if(woman.isChecked()){
? ? ? ? ? ? result+="性別:"+woman.getText().toString()+"\n"+"設(shè)置:";
? ? ? ? }
? ? ? ? if(auto.isChecked()){
? ? ? ? ? ? result+=auto.getText().toString()+" ";
? ? ? ? }
? ? ? ? if(remember.isChecked()){
? ? ? ? ? ? result+=remember.getText().toString()+" ";
? ? ? ? }
? ? ? ?shower.setText(result);
? ? }
}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:orientation="vertical" ? ? tools:context=".MainActivity"> <LinearLayout ? ? android:layout_width="wrap_content" ? ? android:layout_height="wrap_content" ? ? android:orientation="horizontal"> ? ? <ImageView ? ? ? ? android:layout_width="180dp" ? ? ? ? android:layout_height="159dp" ? ? ? ? android:src="@drawable/qq" /> ? ? <LinearLayout ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="vertical" ? ? ? ? > ? ? ? <TableLayout ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/table1"> ? ? ? ? ? <TableRow> ? ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="用戶名" ? ? ? ? ? ? ? ? android:textColor="#000000" ? ? ? ? ? ? ? ? android:textSize="20dp" /> ? ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/name" ? ? ? ? ? ? ? ? android:layout_width="150dp" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" /> ? ? ? ? ? </TableRow> ? ? ? ? ? <TableRow> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="密碼" ? ? ? ? ? ? ? ? android:textColor="#000000" ? ? ? ? ? ? ? ? android:textSize="20dp" /> ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/password" ? ? ? ? ? ? ? ? android:layout_width="150dp" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" /> ? ? ? ? ? </TableRow> ? ? ? ?<TableRow> ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? android:id="@+id/man" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="男" /> ? ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? android:id="@+id/woman" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="女" /> ? ? ? ? ?</TableRow> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? > ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/auto" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:checked="true" ? ? ? ? ? ? ? ? android:text="自動登錄" ? ? ? ? ? ? ? ? android:textSize="18dp" /> ? ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/remember" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:checked="true" ? ? ? ? ? ? ? ? android:text="記住密碼" ? ? ? ? ? ? ? ? android:textSize="18dp" /> ? ? ? ? </LinearLayout> ? ? </TableLayout> ? ? </LinearLayout> </LinearLayout> ? ? <Button ? ? ? ? android:id="@+id/show" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="注冊" ? ? ? ? android:textSize="20dp" ? ? ? ? /> ? ? <TextView ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="300dp" ? ? ? ? android:id="@+id/shower"/> </LinearLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
flutter實(shí)現(xiàn)發(fā)送驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了flutter發(fā)送驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07
Android uses-permission權(quán)限列表中文注釋版
Android有一個精心設(shè)計(jì)的安全模型。每一個應(yīng)用都有其自己Linux用戶和群組,在單獨(dú)的進(jìn)程和VM上運(yùn)行,不能影響到其他應(yīng)用2014-05-05
Android使用ViewFlipper實(shí)現(xiàn)上下滾動消息
這篇文章主要為大家詳細(xì)介紹了Android使用ViewFlipper實(shí)現(xiàn)上下滾動消息,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07
Android Studio下Flutter環(huán)境搭建圖文教程
這篇文章主要為大家詳細(xì)介紹了Android Studio下Flutter環(huán)境搭建圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07
Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析
這篇文章主要為大家介紹了Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11

