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、項目創建殲歲完成,登錄界面如下圖。