【移動應用開發(fā)技術】Android開發(fā)-記賬App開發(fā)項目分享(一)之用戶登錄_第1頁
【移動應用開發(fā)技術】Android開發(fā)-記賬App開發(fā)項目分享(一)之用戶登錄_第2頁
【移動應用開發(fā)技術】Android開發(fā)-記賬App開發(fā)項目分享(一)之用戶登錄_第3頁
【移動應用開發(fā)技術】Android開發(fā)-記賬App開發(fā)項目分享(一)之用戶登錄_第4頁
【移動應用開發(fā)技術】Android開發(fā)-記賬App開發(fā)項目分享(一)之用戶登錄_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術】Android開發(fā)——記賬App開發(fā)項目分享(一)之用戶登錄

一、題外話:本人java基礎很一般,學java的時候就寫了個notepad的demo,為了順應時代的發(fā)展在去年10月份開始學習android,到現(xiàn)在中間漸漸續(xù)續(xù)的持續(xù)了將近5個月,剛開始我也是下了一堆android的視頻,很可惜只看了前2章老羅的視頻,工作的人了沒那么大的耐心和時間慢慢看下去,依照視頻和網(wǎng)上資料把android的開發(fā)環(huán)境搭起來了,androidSDK+eclipse,中間也嘗試了使用androidstudio,但是一旦出了問題,查找的資料相對Eclipse要少很多,所以對于初學者建議還是用Eclipse~沒有多少基礎,也不想慢慢看視頻,直接就進入實操,期間困難在所難免,但堅持下來收獲也是非常明顯的了,現(xiàn)在我就分享下整個開發(fā)過程,當然也會包括代碼分享~讓其他正在步入android門檻的童鞋可以有個借鑒,減少彎路~二、進入正題:記賬應用的開發(fā)涉及絕大多數(shù)android的UI和sqlite數(shù)據(jù)庫等操作,很適合作為初學者練手,下面是我最開始的設計思路:后面在開發(fā)過程中有修改,還是直接來干貨,我就按照我的開發(fā)順序來依次介紹,首先是登錄界面的功能:UI中運用了LinearLayout+RelativeLayout組合布局的使用,期間有各種屬性的使用,寫一個這樣的界面就可以了解很多UI的屬性了。效果如下圖:xml源碼:

<?xml

version="1.0"

encoding="utf-8"?>

<LinearLayout

xmlns:android="/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:background="#FFFFFF">

<ImageView

android:layout_width="120dp"

android:layout_height="120dp"

android:layout_gravity="center"

android:background="@drawable/logo1"

>

</ImageView>

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="8dp"

android:gravity="center"

android:text="歡迎登錄記賬星"

android:textColor="#57647D"

android:textSize="20sp"

android:textStyle="bold"

>

</TextView>

</LinearLayout>

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

<LinearLayout

android:layout_width="260dp"

android:layout_height="100dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="8dp"

android:background="@drawable/userinfo_border"

android:orientation="vertical"

>

<AutoCompleteTextView

android:id="@+id/username"

android:layout_width="250dp"

android:layout_height="45dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="1dp"

android:background="#FFFFFF"

android:drawableLeft="@drawable/user"

android:drawablePadding="10dp"

android:hint="請輸入您的用戶名"

android:textColor="#3D3D3D"

android:textColorHint="#A3B1CA"

android:textSize="15sp"

>

</AutoCompleteTextView>

<View

android:layout_width="match_parent"

android:layout_height="0.2dp"

android:layout_marginTop="4dp"

android:background="#F2F2F2"

>

</View>

<EditText

android:id="@+id/pwd"

android:layout_width="250dp"

android:layout_height="45dp"

android:layout_gravity="center_horizontal"

android:background="#FFFFFF"

android:drawableLeft="@drawable/password"

android:drawablePadding="10dp"

android:hint="請輸入您的密碼

"

android:inputType="textPassword"

android:textColorHint="#A3B1CA"

android:textSize="15sp"

>

</EditText>

</LinearLayout>

<Button

android:id="@+id/btnLogin"

android:layout_width="260dp"

android:layout_height="48dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="20dp"

android:background="@drawable/normalbtnstyle"

android:gravity="center"

android:text="登

錄"

android:textColor="#FFFFFF"

android:textSize="20sp"

android:textStyle="bold"

>

</Button>

<LinearLayout

android:layout_width="260dp"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_gravity="center"

android:gravity="center"

android:layout_marginTop="10dp">"

<CheckBox

android:id="@+id/cbRememberPwd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_weight="1"

android:checked="false"

android:text="記住密碼"

android:textColor="#5E6A81"

android:textSize="15sp"

/>

<Button

android:id="@+id/btnForgetPwd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#FFFFFF"

android:gravity="right"

android:layout_weight="1"

android:textColor="@drawable/btn_forgetpwd_color"

android:textSize="15sp"

android:text="忘記密碼?"/>

</LinearLayout>

</LinearLayout>

<RelativeLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="40dp"

android:gravity="center"

android:orientation="vertical"

>

<TextView

android:id="@+id/zhucexinxi"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_marginBottom="5dp"

android:gravity="center"

android:text="啊,還沒有賬戶?馬上點擊

"

android:textColor="#5E6A81"

android:textSize="14sp"

>

"

</TextView>

<TextView

android:id="@+id/txtRegisterLink"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_marginBottom="5dp"

android:layout_toRightOf="@+id/zhucexinxi"

android:textSize="15sp"

android:textStyle="bold"

>

</TextView>

</RelativeLayout>

</LinearLayout>程序代碼:由于這里面程序代碼無非就是一些判斷控制,這里就只上傳保存按鈕的代碼……btnlogin.setOnClickListener(new

OnClickListener()

{

@Override

public

void

onClick(View

v)

{

if

(uname!=""

&&

uname!=null)

{

if

(rememberPwd.equals("true"))

{

if

(evUsername.getText().toString().trim().length()>0)

{

if

(evUsername.getText().toString().trim().equals(uname))

{

Toast.makeText(Login.this,"登錄成功",Toast.LENGTH_SHORT).show();

Intent

intent

=new

Intent(Login.this,MainActivity.class);

startActivity(intent);

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

finish();

((NotifyApplication)getApplication()).intLoginStatus=1;//登錄激活

((NotifyApplication)getApplication()).strUsername

=

uname;

}else

{

Toast.makeText(Login.this,"用戶名不正確",Toast.LENGTH_SHORT).show();

evUsername.setText("");

evUsername.requestFocus();

}

}else

{

Toast.makeText(Login.this,"用戶名不能為空",Toast.LENGTH_SHORT).show();

evUsername.requestFocus();

}

}else

{

if

(evUsername.getText().toString().trim().length()>0)

{

if

(evPwd.getText().toString().trim().length()>5)

{

if

(evUsername.getText().toString().trim().equals(uname))

{

if

(evPwd.getText().toString().equals(pwd))

{

Toast.makeText(Login.this,"登錄成功",Toast.LENGTH_SHORT).show();

Intent

intent

=new

Intent(Login.this,MainActivity.class);

startActivity(intent);

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

finish();

((NotifyApplication)getApplication()).intLoginStatus=1;//登錄激活

((NotifyApplication)getApplication()).strUsername

=

uname;

}else

{

Toast.makeText(Login.this,"密碼不正確",Toast.LENGTH_SHORT).show();

evPwd.setText("");

evPwd.requestFocus();

}

}else

{

Toast.makeText(Login.this,"用戶名不正確",Toast.LENGTH_SHORT).show();

evUsername.setText("");

evUsername.requestFocus();

}

}else

{

Toast.makeText(Login.this,"密碼長度至少為6",Toast.LENGTH_SHORT).show();

evPwd.setText("");

evPwd.requestFocus();

}

}else

{

Toast.makeText(Login.this,"用戶名不能為空",Toast.LENGTH_SHORT).show();

evUsername.requestFocus();

}

}

}else

{

Toast.makeText(Login.this,"您還未注冊,請點擊下方注冊",Toast.LENGTH_SHORT).show();

}

}

});在現(xiàn)在看來這個頁面有難度的地方,就是“注冊”標簽的點擊鏈接功能的實現(xiàn),需要用到SpannableString這個類,實現(xiàn)該處具體源碼如下:txtRegisterLink=(TextView)findViewById(R.id.txtRegisterLink);

String

str2="注冊";

SpannableString

spans

=

new

SpannableString(str2);

//點擊文本鏈接事件

spans.setSpan(new

ClickableSpan()

{

@Override

public

void

onClick(View

widget)

{

if

(uname==null

||

uname=="")

{

Intent

intent

=

new

Intent(Login.this,

Register.class);

startActivity(intent);

finish();

}else{

Toast.makeText(Login.this,"您已注冊,不能重復注冊",Toast.LENGTH_SHORT).show();

}

}

},

0,

str2.length(),

Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

txtRegisterLink.setText(spans);

接著寫~~~有用戶登錄界面,當然就需要用戶注冊界面了,上面也有貼出在用戶登錄界面通過link調(diào)轉到注冊界面的代碼,下面就直接說注冊界面的功能點:效果圖:注冊界面的xml代碼:<?xml

version="1.0"

encoding="utf-8"?>

<LinearLayout

xmlns:android="/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#FFFFFF"

android:layout_gravity="center_horizontal"

android:orientation="vertical"

>

<LinearLayout

android:layout_width="260dp"

android:layout_height="220dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="40dp"

android:background="@drawable/userinfo_border"

android:orientation="vertical"

>

<EditText

android:id="@+id/username"

android:layout_width="250dp"

android:layout_height="45dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="1dp"

android:background="#FFFFFF"

android:drawableLeft="@drawable/user"

android:drawablePadding="6sp"

android:hint="請輸入您的用戶名"

android:textColor="#3D3D3D"

android:textColorHint="#A3B1CA"

android:textSize="15sp"

>

</EditText>

<View

android:layout_width="match_parent"

android:layout_height="0.2dp"

android:layout_marginTop="4dp"

android:background="#F2F2F2"

>

</View>

<EditText

android:id="@+id/RegPwd"

android:layout_width="250dp"

android:layout_height="45dp"

android:layout_gravity="center_horizontal"

android:background="#FFFFFF"

android:drawableLeft="@drawable/password"

android:drawablePadding="6sp"

android:hint="請輸入您的密碼

"

android:inputType="textPassword"

android:textColorHint="#A3B1CA"

android:textSize="15sp"

>

</EditText>

<View

android:layout_width="match_parent"

android:layout_height="0.2dp"

android:layout_marginTop="4dp"

android:background="#F2F2F2"

>

</View>

<EditText

android:id="@+id/RegPwdAgain"

android:layout_width="250dp"

android:layout_height="45dp"

android:layout_gravity="center_horizontal"

android:background="#FFFFFF"

android:drawableLeft="@drawable/password"

android:drawablePadding="6sp"

android:hint="請再次輸入您的密碼"

android:inputType="textPassword"

android:textColorHint="#A3B1CA"

android:textSize="15sp"

>

</EditText>

<View

android:layout_width="match_parent"

android:layout_height="0.2dp"

android:layout_marginTop="2dp"

android:background="#F2F2F2"

>

</View>

<TextView

android:layout_width="match_parent"

android:layout_height="16dp"

android:layout_gravity="center_horizontal"

android:text

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論