網站首頁 編程語言 正文
本文實例為大家分享了Android實現注冊界面的具體代碼,供大家參考,具體內容如下
LinearLayout 控制布局
TextView 用于顯示文字
EditText 輸入框
RadioGroup 單選按鈕和RadioButton一起用
CheckBox 復選框
Spinner 下拉框
源碼:
register.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:orientation="vertical" android:layout_width="match_parent" ? ? android:layout_height="match_parent"> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? > ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="6dp" ? ? ? ? ? ? android:layout_marginTop="10dp" ? ? ? ? ? ? android:text="用戶名:" ? ? ? ? ? ? android:textSize="15dp" ? ? ? ? ? ? android:textColor="@color/colorPrimary" ? ? ? ? ? ? /> ? ? ? ? <EditText ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="6dp" ? ? ? ? ? ? android:layout_marginTop="10dp" ? ? ? ? ? ? android:hint="輸入2-10個字符" ? ? ? ? ? ? android:textColor="@color/colorPrimary" ? ? ? ? ? ? android:layout_weight="1"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? > ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="6dp" ? ? ? ? ? ? android:layout_marginTop="10dp" ? ? ? ? ? ? android:text="密碼: ? ?" ? ? ? ? ? ? android:textSize="15dp" ? ? ? ? ? ? android:textColor="@color/colorPrimary" ? ? ? ? ? ? /> ? ? ? ? <EditText ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="6dp" ? ? ? ? ? ? android:layout_marginTop="10dp" ? ? ? ? ? ? android:hint="輸入6-10個字符" ? ? ? ? ? ? android:textColor="@color/colorPrimary" ? ? ? ? ? ? android:layout_weight="1"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? > ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="6dp" ? ? ? ? ? ? android:layout_marginTop="23dp" ? ? ? ? ? ? android:text="性別選擇: ? ?" ? ? ? ? ? ? android:textSize="15dp" ? ? ? ? ? ? android:textColor="@color/colorPrimary" ? ? ? ? ? ? /> ? ? ? ? <RadioGroup ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:layout_marginLeft="10dp" ? ? ? ? ? ? android:layout_marginTop="10dp"> ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:layout_marginLeft="30dp" ? ? ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? ? ? android:text="男"/> ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:layout_marginLeft="30dp" ? ? ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? ? ? android:text="女"/> ? ? ? ? </RadioGroup> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="5dp" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:textSize="15dp" ? ? ? ? ? ? android:text="愛好選擇:" ? ? ? ? ? ? android:textColor="@color/colorPrimaryDark"/> ? ? ? ? <CheckBox ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="游泳"/> ? ? ? ? <CheckBox ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="打球"/> ? ? ? ? <CheckBox ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="看書"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="5dp" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:textSize="15dp" ? ? ? ? ? ? android:text="所在地"/> ? ? ? ? <Spinner ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginTop="6dp" ? ? ? ? ? ? android:layout_marginLeft="10dp" ? ? ? ? ? ? android:entries="@array/citys"> ? ? ? ? </Spinner> ? ? </LinearLayout> ? ? <Button ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="注冊" ? ? ? ? android:textColor="@color/colorPrimaryDark"/> </LinearLayout>
strings.xml
<resources> ? ? <string name="app_name">Register</string> ? ? <string-array name="citys"> ? ? ? ? <item>贛州</item> ? ? ? ? <item>上海</item> ? ? ? ? <item>廣州</item> ? ? ? ? <item>深圳</item> ? ? ? ? <item>北京</item> ? ? ? ? <item>湖南</item> ? ? ? ? <item>湖北</item> ? ? ? ? <item>南寧</item> ? ? ? ? <item>廈門</item> ? ? </string-array> </resources>
Main.java
package com.example.hsy.register;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.register);
? ? }
}
效果圖
原文鏈接:https://blog.csdn.net/gh6267/article/details/77853277
相關推薦
- 2023-11-22 Linux的vim命令如何使用
- 2022-11-01 Kotlin?ContentProvider使用方法介紹_Android
- 2023-12-13 idea git只查看某個人提交的代碼記錄
- 2022-09-26 React?Native?中添加自定義字體的方法_React
- 2022-09-13 Python判斷和循環語句的分析與應用_python
- 2022-09-29 Python組合數據類型詳解_python
- 2022-12-23 Python中的文件輸入輸出問題_python
- 2022-02-28 npm ERR! While resolving: undefined@undefined npm
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支