欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android登錄界面的實(shí)現(xiàn)代碼分享

 更新時(shí)間:2016年11月04日 09:51:26   作者:文明的小流氓  
好久沒(méi)有搞android項(xiàng)目了,手都有點(diǎn)松了,今天因?yàn)轫?xiàng)目的需要,繼續(xù)弄android知識(shí),在項(xiàng)目中登錄界面是項(xiàng)目中比較常見(jiàn)的最基本的功能,對(duì)android登錄界面的實(shí)現(xiàn)感興趣的朋友一起學(xué)習(xí)吧

最近由于項(xiàng)目需要,寶寶好久沒(méi)搞Android啦,又是因?yàn)轫?xiàng)目需要,現(xiàn)在繼續(xù)弄Android,哎,說(shuō)多了都是淚呀,別的不用多說(shuō),先搞一個(gè)登錄界面練練手,登錄界面可以說(shuō)是Android項(xiàng)目中最常用也是最基本的,如果這個(gè)都搞不定,那可以直接去跳21世紀(jì)樓啦。

廢話(huà)不多說(shuō),先上效果圖了,如果大家感覺(jué)還不錯(cuò),請(qǐng)參考實(shí)現(xiàn)代碼吧。

相信這種渣渣布局對(duì)很多人來(lái)說(shuō)太簡(jiǎn)單啦,直接上布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:custom="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fitsSystemWindows="true" > 
<RelativeLayout 
android:id="@+id/login_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="20dp" 
android:layout_marginRight="20dp" 
android:gravity="center" > 
<FrameLayout 
android:id="@+id/username_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="55dp" 
android:gravity="center" > 
<!-- android:inputType="number" --> 
<EditText 
android:id="@+id/username" 
android:layout_width="fill_parent" 
android:layout_height="40dp" 
android:layout_marginTop="5dp" 
android:maxLength="20" 
android:paddingLeft="55dp" 
android:paddingRight="60dp" > 
</EditText> 
<ImageView 
android:layout_width="22dp" 
android:layout_height="21dp" 
android:layout_gravity="left|center_vertical" 
android:layout_marginStart="10dp" 
android:background="@drawable/username" 
android:visibility="visible" /> 
<TextView 
android:id="@+id/contry_sn" 
android:layout_width="40dp" 
android:layout_height="50dp" 
android:layout_gravity="left|center_vertical" 
android:layout_marginTop="4dp" 
android:gravity="center" 
android:text="+62" 
android:textColor="@android:color/black" 
android:textSize="18sp" 
android:visibility="invisible" /> 
<Button 
android:id="@+id/bt_username_clear" 
android:layout_width="35dp" 
android:layout_height="35dp" 
android:layout_gravity="right|center_vertical" 
android:layout_marginRight="10dp" 
android:background="@drawable/email_delete_pressed" 
android:visibility="invisible" /> 
</FrameLayout> 
<FrameLayout 
android:id="@+id/usercode_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_below="@id/username_layout" 
android:layout_marginTop="6dp" 
android:gravity="center" > 
<EditText 
android:id="@+id/password" 
android:layout_width="fill_parent" 
android:layout_height="40dp" 
android:inputType="textPassword" 
android:maxLength="20" 
android:paddingLeft="55dp" 
android:paddingRight="60dp" > 
</EditText> 
<ImageView 
android:layout_width="18dp" 
android:layout_height="21dp" 
android:layout_gravity="left|center_vertical" 
android:layout_marginStart="10dp" 
android:background="@drawable/password" /> 
<Button 
android:id="@+id/bt_pwd_eye" 
android:layout_width="40dp" 
android:layout_height="40dp" 
android:layout_gravity="right|center_vertical" 
android:layout_marginRight="10dp" 
android:background="@drawable/password_close" /> 
<Button 
android:id="@+id/bt_pwd_clear" 
android:layout_width="35dp" 
android:layout_height="35dp" 
android:layout_gravity="right|center_vertical" 
android:layout_marginRight="45dp" 
android:background="@drawable/email_delete_pressed" 
android:visibility="invisible" /> 
</FrameLayout> 
<Button 
android:id="@+id/login" 
android:layout_width="fill_parent" 
android:layout_height="40dp" 
android:layout_below="@id/usercode_layout" 
android:layout_marginTop="30dp" 
android:background="@drawable/login_selector" 
android:gravity="center" 
android:text="登錄" 
android:textColor="@android:color/white" /> 
<Button 
android:id="@+id/forgive_pwd" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignRight="@id/login" 
android:layout_below="@id/login" 
android:background="#00000000" 
android:text="忘記密碼?" 
android:textColor="@drawable/text_color_selector" 
android:textSize="16sp" /> 
<Button 
android:id="@+id/register" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignLeft="@id/login" 
android:layout_below="@id/login" 
android:background="#00000000" 
android:gravity="left|center_vertical" 
android:text="注冊(cè)" 
android:textColor="@drawable/text_color_selector" 
android:textSize="16sp" 
android:visibility="visible" /> 
</RelativeLayout> 
</RelativeLayout> 

MainActivity如下:

package com.example.logindemo; 
import android.support.v7.app.ActionBarActivity; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.text.method.HideReturnsTransformationMethod; 
import android.text.method.PasswordTransformationMethod; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
import android.os.Bundle; 
/** 
* 登錄界面Demo 
* 
* @author ZHY 
* 
*/ 
public class MainActivity extends ActionBarActivity implements OnClickListener { 
private EditText username, password; 
private Button bt_username_clear; 
private Button bt_pwd_clear; 
private Button forgive_pwd; 
private Button bt_pwd_eye; 
private Button login; 
private Button register; 
private boolean isOpen = false; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
initView(); 
} 
private void initView() { 
username = (EditText) findViewById(R.id.username); 
// 監(jiān)聽(tīng)文本框內(nèi)容變化 
username.addTextChangedListener(new TextWatcher() { 
@Override 
public void onTextChanged(CharSequence s, int start, int before, 
int count) { 
// 獲得文本框中的用戶(hù) 
String user = username.getText().toString().trim(); 
if ("".equals(user)) { 
// 用戶(hù)名為空,設(shè)置按鈕不可見(jiàn) 
bt_username_clear.setVisibility(View.INVISIBLE); 
} else { 
// 用戶(hù)名不為空,設(shè)置按鈕可見(jiàn) 
bt_username_clear.setVisibility(View.VISIBLE); 
} 
} 
@Override 
public void beforeTextChanged(CharSequence s, int start, int count, 
int after) { 
} 
@Override 
public void afterTextChanged(Editable s) { 
} 
}); 
password = (EditText) findViewById(R.id.password); 
// 監(jiān)聽(tīng)文本框內(nèi)容變化 
password.addTextChangedListener(new TextWatcher() { 
@Override 
public void onTextChanged(CharSequence s, int start, int before, 
int count) { 
// 獲得文本框中的用戶(hù) 
String pwd = password.getText().toString().trim(); 
if ("".equals(pwd)) { 
// 用戶(hù)名為空,設(shè)置按鈕不可見(jiàn) 
bt_pwd_clear.setVisibility(View.INVISIBLE); 
} else { 
// 用戶(hù)名不為空,設(shè)置按鈕可見(jiàn) 
bt_pwd_clear.setVisibility(View.VISIBLE); 
} 
} 
@Override 
public void beforeTextChanged(CharSequence s, int start, int count, 
int after) { 
} 
@Override 
public void afterTextChanged(Editable s) { 
} 
}); 
bt_username_clear = (Button) findViewById(R.id.bt_username_clear); 
bt_username_clear.setOnClickListener(this); 
bt_pwd_clear = (Button) findViewById(R.id.bt_pwd_clear); 
bt_pwd_clear.setOnClickListener(this); 

bt_pwd_eye = (Button) findViewById(R.id.bt_pwd_eye); 
bt_pwd_eye.setOnClickListener(this); 
login = (Button) findViewById(R.id.login); 
login.setOnClickListener(this); 
egister = (Button) findViewById(R.id.register); 
register.setOnClickListener(this); 
forgive_pwd = (Button) findViewById(R.id.forgive_pwd); 
forgive_pwd.setOnClickListener(this); 
} 
@Override 
public void onClick(View v) { 
switch (v.getId()) { 
case R.id.bt_username_clear: 
// 清除登錄名 
username.setText(""); 
break; 
case R.id.bt_pwd_clear: 
// 清除密碼 
password.setText(""); 
break; 
case R.id.bt_pwd_eye: 
// 密碼可見(jiàn)與不可見(jiàn)的切換 
if (isOpen) { 
isOpen = false; 
} else { 
isOpen = true; 
} 
// 默認(rèn)isOpen是false,密碼不可見(jiàn) 
changePwdOpenOrClose(isOpen); 
break; 
case R.id.login: 
// TODO 登錄按鈕 
break; 
case R.id.register: 
// 注冊(cè)按鈕 
Toast.makeText(MainActivity.this, "注冊(cè)", 0).show(); 
break; 
case R.id.forgive_pwd: 
// 忘記密碼按鈕 
Toast.makeText(MainActivity.this, "忘記密碼", 0).show(); 
break; 
default: 
break; 
} 
} 
/** 
* 密碼可見(jiàn)與不可見(jiàn)的切換 
* 
* @param flag 
*/ 
private void changePwdOpenOrClose(boolean flag) { 
// 第一次過(guò)來(lái)是false,密碼不可見(jiàn) 
if (flag) { 
// 密碼可見(jiàn) 
bt_pwd_eye.setBackgroundResource(R.drawable.password_open); 
// 設(shè)置EditText的密碼可見(jiàn) 
password.setTransformationMethod(HideReturnsTransformationMethod 
.getInstance()); 
} else { 
// 密碼不接見(jiàn) 
bt_pwd_eye.setBackgroundResource(R.drawable.password_close); 
// 設(shè)置EditText的密碼隱藏 
password.setTransformationMethod(PasswordTransformationMethod 
.getInstance()); 
} 
} 
} 

Ok,就是這么簡(jiǎn)單,效果完成。

以上所述是小編給大家介紹的Android登錄界面的實(shí)現(xiàn)代碼分享,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android自定義shape的使用示例

    Android自定義shape的使用示例

    本文主要介紹自定義shape(定義矩形、定義邊框顏色、定義圓角弧度),具體代碼如下,感興趣的各位可以參考下哈,希望對(duì)大家有所幫助
    2013-06-06
  • ActivityManagerService之Service啟動(dòng)過(guò)程解析

    ActivityManagerService之Service啟動(dòng)過(guò)程解析

    這篇文章主要為大家介紹了ActivityManagerService之Service啟動(dòng)過(guò)程解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Ubantu16.04進(jìn)行Android 8.0源碼編譯的流程

    Ubantu16.04進(jìn)行Android 8.0源碼編譯的流程

    這篇文章主要介紹了Ubantu16.04進(jìn)行Android 8.0源碼編譯的相關(guān)資料,需要的朋友可以參考下
    2018-02-02
  • android實(shí)現(xiàn)緩存圖片等數(shù)據(jù)

    android實(shí)現(xiàn)緩存圖片等數(shù)據(jù)

    本文給大家分享的是Android采用LinkedHashMap自帶的LRU 算法緩存數(shù)據(jù)的方法和示例,有需要的小伙伴可以參考下。
    2015-07-07
  • Android實(shí)現(xiàn)TextView字符串關(guān)鍵字變色的方法

    Android實(shí)現(xiàn)TextView字符串關(guān)鍵字變色的方法

    這篇文章顯示給大家介紹了字符串中關(guān)鍵字變色的實(shí)現(xiàn)方法,而后又拓展介紹了在Android中如何實(shí)現(xiàn)搜索關(guān)鍵字變色,相信對(duì)各位Android開(kāi)發(fā)者們具有一定的參考借鑒價(jià)值,感興趣的朋友們下面來(lái)一起看看吧。
    2016-10-10
  • 浮動(dòng)AppBar中的textField焦點(diǎn)回滾問(wèn)題解決

    浮動(dòng)AppBar中的textField焦點(diǎn)回滾問(wèn)題解決

    這篇文章主要為大家介紹了浮動(dòng)AppBar中的textField焦點(diǎn)回滾問(wèn)題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android實(shí)現(xiàn)朋友圈評(píng)論回復(fù)列表

    Android實(shí)現(xiàn)朋友圈評(píng)論回復(fù)列表

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)朋友圈評(píng)論回復(fù)列表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android幀率監(jiān)測(cè)與優(yōu)化技巧

    Android幀率監(jiān)測(cè)與優(yōu)化技巧

    Android 應(yīng)用的性能優(yōu)化是開(kāi)發(fā)過(guò)程中至關(guān)重要的一環(huán),而幀率(Frame Rate)是評(píng)估應(yīng)用性能的一個(gè)關(guān)鍵指標(biāo),在本文中,我們將深入探討如何監(jiān)測(cè) Android 應(yīng)用的幀率,以及如何通過(guò)代碼示例來(lái)優(yōu)化應(yīng)用的性能,需要的朋友可以參考下
    2023-10-10
  • linphone-sdk-android版本號(hào)生成解析

    linphone-sdk-android版本號(hào)生成解析

    這篇文章主要為大家介紹了linphone-sdk-android版本號(hào)生成解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • 淺談Android硬件加速原理與實(shí)現(xiàn)簡(jiǎn)介

    淺談Android硬件加速原理與實(shí)現(xiàn)簡(jiǎn)介

    這篇文章主要介紹了淺談Android硬件加速原理與實(shí)現(xiàn)簡(jiǎn)介,本文嘗試從底層硬件原理,一直到上層代碼實(shí)現(xiàn),對(duì)硬件加速技術(shù)進(jìn)行簡(jiǎn)單介紹,感興趣的小伙伴們可以參考一下
    2018-07-07

最新評(píng)論