android登录注册界面
A. android登录问题
创建一个全局变量,标记你是否已经登录。每次点击的时候做判断,已经登录了就不弹登录界面了。
B. Android Studio-基于sqlLITE实现登录注册功能
继启动界面之后,现在开始做登录界面和注册界面。需要看启动界面教学的,请戳我的博客 Android Studio之启动界面教学 https://www.jianshu.com/p/7e0955291b18?tdsourcetag=s_pctim_aiomsg
其实安卓的登录注册,和java是一样的,甚至于是极简版的JAVA登录注册,安卓太智能了,数据保存在sqllite中,完全不需要导包,而且还伴有可视化界面,简直无敌,安卓可以说是目前我们学过的最简单的语言,只是大家没有好好学罢了。如果大家认真学习,会发现真的超简单....
闲话不多说,接下来直接开始。
好啦,各位同学,我想我写的够详细了,希望能够帮到大家。
咱们就差一个备忘录了,
未完待续....
C. 如何使用Android Studio开发用户登录界面
一个登录界面需要有:
登录、注册按钮(Button)
用户名、密码输入框(TextView,EditView)
用户协议连接
忘记密码按钮
想好的有哪些控件后,开始设计界面大概样式,比如这个样子:
安卓登录界面就写完了。
D. android作业创建用户登陆和密码
布局文件:
<RelativeLayoutxmlns: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="#efefef"
tools:context="cn.teachcourse.activity.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#2088c2"
android:orientation="horizontal"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:text="登录界面"
android:textSize="22sp"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"/>
</LinearLayout>
<!--输入用户名框-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/center_point"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:drawableLeft="@drawable/user_login_icon"/>
<EditText
android:id="@+id/user_name_ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="@string/username_hint"/>
</LinearLayout>
<!--输入密码框-->
<LinearLayout
android:id="@+id/pass_word_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/center_point"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:drawableLeft="@drawable/user_login_lock"/>
<EditText
android:id="@+id/pass_word_ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="@string/password_hint"
android:inputType="textPassword"/>
</LinearLayout>
<Button
android:id="@+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pass_word_ll"
android:layout_margin="10dp"
android:background="@drawable/blue_bg"
android:text="@string/login_str"
android:textColor="#FFFFFF"/>
<View
android:id="@+id/center_point"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
实现代码:
packagecn.teachcourse.activity;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
importcn.teachcourse.common.BaseActivity;
importcn.teachcourse.utils.SharedPreferenceUtil;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.text.TextUtils;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
/**
*@authorTeachCourse博客保存数据的的方法有:
*1、网络存储
*2、数据库sqlite存储
*3、SharedPreferences本地化存储
*4、File文件存储
*四种存储数据的方法,对应的Demo:
*NetworkDemo、SQLiteDemo、SharedPreferencesDemo和FileDemo
*
*/
{
privateEditTextmUserName_ET,mPassword_ET;
privateButtonmLogin_btn;
privateStringusername;
privateStringpassword;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
//activity_main编辑一个注册登录界面
setContentView(R.layout.activity_main);
SharedPreferenceUtil.initPreference(this);
initView();
}
@Override
protectedvoidonResume(){
//检查SharedPreferences文件中是否保存有用户名和密码
super.onResume();
StringusernameStr=SharedPreferenceUtil.getString("username",null);
StringpasswordStr=SharedPreferenceUtil.getString("password",null);
if(!TextUtils.isEmpty(usernameStr)){
mUserName_ET.setText(usernameStr);
}elseif(!TextUtils.isEmpty(passwordStr)){
mPassword_ET.setText(passwordStr);
}
}
privatevoidinitView(){
mLogin_btn=(Button)findViewById(R.id.login_btn);
mUserName_ET=(EditText)findViewById(R.id.user_name_ET);
mPassword_ET=(EditText)findViewById(R.id.pass_word_ET);
mLogin_btn.setOnClickListener(this);
}
@Override
publicvoidonClick(Viewv){
switch(v.getId()){
caseR.id.login_btn:
login();
break;
}
}
privatevoidlogin(){
username=mUserName_ET.getText().toString().trim();
password=mPassword_ET.getText().toString().trim();
//这里只验证格式是否合法,不验证用户名和密码的正确性,SharedPreferences将数据存储到本地
if(checkPhone(username)&&checkNotNull(password)){
SharedPreferenceUtil.putString("username",username);
SharedPreferenceUtil.putString("password",password);
toSecondActivity();
}
}
privatevoidtoSecondActivity(){
Intentintent=newIntent(this,SecondActivity.class);
Bundlebundle=newBundle();
bundle.putString("username",username);
bundle.putString("password",password);
intent.putExtras(bundle);
startActivity(intent);
MainActivity.this.finish();
}
/**
*@paramvalue需要验证的用户名
*@return
*/
privatebooleancheckNotNull(Stringvalue){
if(!TextUtils.isEmpty(value)){
if(value.length()<6){
Toast.makeText(this,"密码填写不合法!",Toast.LENGTH_LONG).show();//号码填写不正确
returnfalse;
}else{
returntrue;
}
}else{
Toast.makeText(this,"密码不能为空",Toast.LENGTH_LONG).show();
returnfalse;
}
}
/**
*@paramphone需要验证的手机号码
*@return
*/
privatebooleancheckPhone(Stringphone){
if(!TextUtils.isEmpty(phone)){
if(ismobileNO(phone)){
returntrue;
}else{
Toast.makeText(this,"号码填写不正确",Toast.LENGTH_LONG).show();//号码填写不正确
returnfalse;
}
}else{
Toast.makeText(this,"号码不能为空",Toast.LENGTH_LONG).show();//不能为空
returnfalse;
}
}
/**
*手机号码的验证,严格验证
*
*@param/mobiles要验证的手机号码
*@return
*/
publicstaticbooleanismobileNO(Stringmobiles){
if(TextUtils.isEmpty(mobiles)){
returnfalse;
}
Patternp=Pattern
.compile("^((13[0-9])|(14[5,7])|(15[^4,\D])|(17[0,6,7,8])|(18[0-9]))\d{8}$");
Matcherm=p.matcher(mobiles);
returnm.matches();
}
}
效果图:
E. android怎么做动态的登陆界面
设计android的登录界面的方法:
UI实现的代码如下:
1、背景设置图片:
background_login.xml
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFACDAE5"
android:endColor="#FF72CAE1"
android:angle="45"
/>
</shape>
2、圆角白框
效果图上面的并不是白框,其实框是白色的,只是设置了透明值,也是靠一个xml文件实现的。
background_login_div.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">
<solidandroid:color="#55FFFFFF"/>
<!--设置圆角
注意:bottomRightRadius是左下角而不是右下角bottomLeftRadius右下角-->
<cornersandroid:topLeftRadius="10dp"android:topRightRadius="10dp"
android:bottomRightRadius="10dp"android:bottomLeftRadius="10dp"/>
</shape>
3、界面布局:
login.xml
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_login">
<!--padding内边距layout_margin外边距
android:layout_alignParentTop布局的位置是否处于顶部-->
<RelativeLayout
android:id="@+id/login_div"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dip"
android:layout_margin="15dip"
android:background="@drawable/background_login_div_bg">
<!--账号-->
<TextView
android:id="@+id/login_user_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="@string/login_label_username"
style="@style/normalText"/>
<EditText
android:id="@+id/username_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/login_username_hint"
android:layout_below="@id/login_user_input"
android:singleLine="true"
android:inputType="text"/>
<!--密码text-->
<TextView
android:id="@+id/login_password_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/username_edit"
android:layout_marginTop="3dp"
android:text="@string/login_label_password"
style="@style/normalText"/>
<EditText
android:id="@+id/password_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_password_input"
android:password="true"
android:singleLine="true"
android:inputType="textPassword"/>
<!--登录button-->
<Button
android:id="@+id/signin_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/password_edit"
android:layout_alignRight="@id/password_edit"
android:text="@string/login_label_signin"
android:background="@drawable/blue_button"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextViewandroid:id="@+id/register_link"
android:text="@string/login_register_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textColor="#888"
android:textColorLink="#FF0066CC"/>
<ImageViewandroid:id="@+id/miniTwitter_logo"
android:src="@drawable/cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="25dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="25dp"/>
<ImageViewandroid:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/miniTwitter_logo"
android:layout_alignBottom="@id/miniTwitter_logo"
android:paddingBottom="8dp"/>
</RelativeLayout>
</LinearLayout>
4、java源代码,Java源文件比较简单,只是实例化Activity,去掉标题栏。
packagecom.mytwitter.acitivity;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Window;
{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
}
}
5、实现效果如下:
F. android studio登录注册
我们项目的前提是你已经将基本的运行环境及sdk都已经安装好了,读者可自行网络环境配置相关内容,本文不再赘述。右键点击new-->Mole,Mole相当于新建了一个项目。如图所示
选择Android Application,点击next
将My Mole 和app改成自己项目相应的名字,同时选择支持的Android版本
这一步我们选择Blank Activity,自己手动编写登录界面,而不依赖系统内置的Login Activity,一直点击next,最后点击finish就完成了项目的创建
在project下我们可以看到出现了我们刚才创建的login项目
展开res/layout,点击打开activity_main.xml文件,在这个文件里我们将完成登录界面的编写
这是初始的主界面,还没有经过我们编写的界面,Android Studio有一个很强大的预览功能,相当给力
我们将activity_main.xml的代码替换成如下代码:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:stretchColumns="0,3">
<TableRow>
<TextView />
<TextView
android:text="账 号:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
/>
<EditText
android:id="@+id/account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:minWidth="220px"/>
<TextView />
</TableRow>
<TableRow android:layout_marginTop="20px">
<TextView />
<TextView
android:text="密 码:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="220px"
android:textSize="24px"
android:inputType="textPassword"/>
<TextView />
</TableRow>
<TableRow android:layout_marginTop="20px">
<TextView />
<Button
android:id="@+id/login"
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/quit"
android:text="退出"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView />
</TableRow>
</TableLayout>
预览效果如图
10
使用Android 手机进行测试,大功告成
G. androidstudio注册登录界面密码错误和用户名不存在
androidstudio注册登录界面密码错误和用户名不存在的原因有:
1、帐号没激活或者没有进行信息回复,去邮箱或者其它地方进行激活或者确认、登录时分清楚大小写,注册时字母是大写请用大写,小写请用小写。
2、帐号未通过GM的认可,并未看清楚到底注册成功没有,注册号已被盗取,并被注销,请找客服申诉。
3、有些网站的服务只针对注册会员开放,每次登录时,要出示登记时的会员卡,用户名是名字,密码就是密码呢。用户名不存在的意思就是,出示的用户名没有登记。
4、用户名就是账号的意思。登陆时显示用户名不存在,是指在该平台没有注册过。
H. 如何使用Android Studio开发用户登录界面
使用Android Studio开发用户登录界面是可以直接创建的,创建丛肆步骤如下。
1、点击菜单栏的“File”-->"New"-->“New Project ”。
2、然后输入创建的项目名-->点击"next",。
3、然后点击"Next",选择创建登录界面。
4.然后点击"氏郑睁Fisih"
5、项目创建歼岁完成,登录界面如下图。