成品直播源码推荐,登录和注册两个页面的简单实现
成品直播源码推荐,登录和注册两个页面的简单实现
xml登录界面设计
1 | <?xml version= "1.0" encoding= "utf-8" ?><br><LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:app= "http://schemas.android.com/apk/res-auto" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> tools:context= ".MainActivity" <br> android:orientation= "vertical" <br> <br> ><br> <TextView<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:text= "注册" <br> android:textSize= "35sp" <br> android:gravity= "center" <br> android:background= "#FF5722" <br> /><br><LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "210dp" <br> android:orientation= "horizontal" <br> ><br> <Button<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:background= "@drawable/qq" <br> android:layout_weight= "1" <br> android:text= "用QQ注册" <br> android:gravity= "center" <br> android:textSize= "20sp" <br> /><br> <Button<br> android:layout_width= "wrap_content" <br> android:layout_height= "210dp" <br> android:background= "@drawable/wechat" <br> android:layout_weight= "1" <br> android:text= "用微信注册" <br> android:textSize= "20sp" <br> /><br></LinearLayout><br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" <br> ><br> <ImageView<br> android:id= "@+id/yxlg" <br> android:layout_marginTop= "12dp" <br> android:layout_marginLeft= "80dp" <br> android:layout_width= "30dp" <br> android:layout_height= "30dp" <br> android:background= "@drawable/net" <br> /><br> <TextView<br> android:paddingTop= "5dp" <br> android:paddingBottom= "5dp" <br> android:id= "@+id/yxld" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:text= " 用邮箱登录" <br> android:gravity= "center" <br> android:textSize= "35sp" <br> /><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <TextView<br> android:paddingTop= "12dp" <br> android:layout_width= "wrap_content" <br> android:layout_height= "60dp" <br> android:text= "名字:" <br> android:gravity= "left" <br> android:textSize= "25sp" <br> /><br> <EditText<br> android:id= "@+id/mz" <br> android:paddingTop= "12dp" <br> android:background= "@null" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:textSize= "30sp" <br> <br> /><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br></LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <TextView<br> android:paddingTop= "12dp" <br> android:layout_width= "wrap_content" <br> android:layout_height= "60dp" <br> android:text= "账号:" <br> android:gravity= "left" <br> android:textSize= "25sp" <br> /><br> <EditText<br> android:id= "@+id/zh" <br> android:paddingTop= "12dp" <br> android:background= "@null" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:textSize= "30sp" <br> /><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <TextView<br> android:paddingTop= "12dp" <br> android:layout_width= "wrap_content" <br> android:layout_height= "60dp" <br> android:text= "密码:" <br> android:gravity= "left" <br> android:textSize= "25sp" <br> /><br> <EditText<br> android:password= "true" <br> android:id= "@+id/mm" <br> android:paddingTop= "12dp" <br> android:background= "@null" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:textSize= "30sp" <br> /><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <TextView<br> android:paddingTop= "12dp" <br> android:layout_width= "wrap_content" <br> android:layout_height= "60dp" <br> android:text= "性别: " <br> android:gravity= "left" <br> android:textSize= "25sp" <br> /><br> <RadioGroup<br> android:id= "@+id/xb" <br> android:layout_marginTop= "15dp" <br> android:orientation= "horizontal" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" ><br> <RadioButton<br> android:id= "@+id/nan" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "男" <br> android:textSize= "20sp" <br> /><br><RadioButton<br> android:id= "@+id/nu" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "女" <br> android:textSize= "20sp" <br> /><br> </RadioGroup><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <TextView<br> android:paddingTop= "12dp" <br> android:layout_width= "wrap_content" <br> android:layout_height= "60dp" <br> android:text= "选择你的爱好:" <br> android:gravity= "left" <br> android:textSize= "25sp" <br> /><br> <CheckBox<br> android:id= "@+id/cg" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "唱歌" <br> android:textSize= "20sp" /><br> <CheckBox<br> android:id= "@+id/tw" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "跳舞" <br> android:textSize= "20sp" /><br> <CheckBox<br> android:id= "@+id/ds" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "读书" <br> android:textSize= "20sp" /><br> </LinearLayout><br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/colorAccent" <br> ><br> </LinearLayout><br> <Button<br> android:id= "@+id/btn1" <br> android:layout_width= "match_parent" <br> android:layout_height= "100dp" <br> android:text= "提交" <br> android:textSize= "30sp" <br> /><br></LinearLayout> |
注册功能实现
1 | package com.example.registerlogin;<br> <br>import androidx.appcompat.app.AppCompatActivity;<br> <br>import android.os.Bundle;<br>import android.text.TextUtils;<br>import android.util.Log;<br>import android.view.View;<br>import android.widget.Button;<br>import android.widget.CheckBox;<br>import android.widget.CompoundButton;<br>import android.widget.EditText;<br>import android.widget.RadioGroup;<br>import android.widget.Toast;<br> <br> <br> public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{<br> private EditText mz,zh,mm;<br> private Button btn1;<br> private String name,id,pwd,sex,hobby;<br> private RadioGroup xb;<br> private CheckBox cg,tw,ds;<br> <br> <br> @Override<br> protected void onCreate(Bundle savedInstanceState) {<br> super.onCreate(savedInstanceState);<br> setContentView(R.layout.activity_main);<br> btn1=findViewById(R.id.btn1);<br> mz=findViewById(R.id.mz);<br> zh=findViewById(R.id.mz);<br> mm=findViewById(R.id.mz);<br> cg=findViewById(R.id.cg);<br> tw=findViewById(R.id.tw);<br> ds=findViewById(R.id.ds);<br> xb=findViewById(R.id.xb);<br> <br> btn1.setOnClickListener(MainActivity.this);<br> xb.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {<br> @Override<br> public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {<br> { switch (checkedId){<br> case R.id.nan:<br> sex = "男" ;<br> break ;<br> case R.id.nu:<br> sex= "女" ;<br> break ;<br> <br> }<br> }<br> }<br> });<br> }<br> private void getData(){<br> name=mz. getText ().toString().trim();<br> id=zh. getText ().toString().trim();<br> pwd=mm. getText ().toString().trim();<br> }<br> public void onClick(View v) {<br> switch (v.getId()) {<br> case R.id.btn1:<br> getData();<br> <br> if (TextUtils.isEmpty(name)) {<br> <br> Toast.makeText(MainActivity.this, "请输入名字" , Toast.LENGTH_SHORT).show();<br> } else if (TextUtils.isEmpty(id)) {<br> <br> Toast.makeText(MainActivity.this, "请输入账号" , Toast.LENGTH_SHORT).show();<br> } else if (TextUtils.isEmpty(pwd)) {<br> <br> Toast.makeText(MainActivity.this, "请输入密码" , Toast.LENGTH_SHORT).show();<br> } else if (TextUtils.isEmpty(sex)) {<br> <br> Toast.makeText(MainActivity.this, "请输入性别" , Toast.LENGTH_SHORT).show();<br> } else if (TextUtils.isEmpty(hobby)) {<br> <br> Toast.makeText(MainActivity.this, "请输入爱好" , Toast.LENGTH_SHORT).show();<br> } else {<br> Toast.makeText(MainActivity.this, "注册成功" , Log.i( "MainActivity" , "检测到你的注册信息:" + "名字:" + name + " 邮箱:" + id + " 性别:" + sex+ " 爱好:" +hobby));<br> }<br> break ;<br> }<br> }<br> <br> public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){<br> String motion =buttonView. getText ().toString();<br> if (isChecked){<br> if (!hobby.contains(motion)){<br> hobby = hobby + motion;<br> }<br> } else {<br> if (hobby.contains(motion)){<br> <br> hobby=hobby.replace(motion, "" );<br> }<br> <br> }<br>}<br> <br>} |
以上就是 成品直播源码推荐,登录和注册两个页面的简单实现,更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现