最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

廢話不多說(shuō),先上效果圖了,如果大家感覺還不錯(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)聽文本框內(nèi)容變化 
username.addTextChangedListener(new TextWatcher() { 
@Override 
public void onTextChanged(CharSequence s, int start, int before, 
int count) { 
// 獲得文本框中的用戶 
String user = username.getText().toString().trim(); 
if ("".equals(user)) { 
// 用戶名為空,設(shè)置按鈕不可見 
bt_username_clear.setVisibility(View.INVISIBLE); 
} else { 
// 用戶名不為空,設(shè)置按鈕可見 
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)聽文本框內(nèi)容變化 
password.addTextChangedListener(new TextWatcher() { 
@Override 
public void onTextChanged(CharSequence s, int start, int before, 
int count) { 
// 獲得文本框中的用戶 
String pwd = password.getText().toString().trim(); 
if ("".equals(pwd)) { 
// 用戶名為空,設(shè)置按鈕不可見 
bt_pwd_clear.setVisibility(View.INVISIBLE); 
} else { 
// 用戶名不為空,設(shè)置按鈕可見 
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: 
// 密碼可見與不可見的切換 
if (isOpen) { 
isOpen = false; 
} else { 
isOpen = true; 
} 
// 默認(rèn)isOpen是false,密碼不可見 
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; 
} 
} 
/** 
* 密碼可見與不可見的切換 
* 
* @param flag 
*/ 
private void changePwdOpenOrClose(boolean flag) { 
// 第一次過來(lái)是false,密碼不可見 
if (flag) { 
// 密碼可見 
bt_pwd_eye.setBackgroundResource(R.drawable.password_open); 
// 設(shè)置EditText的密碼可見 
password.setTransformationMethod(HideReturnsTransformationMethod 
.getInstance()); 
} else { 
// 密碼不接見 
bt_pwd_eye.setBackgroundResource(R.drawable.password_close); 
// 設(shè)置EditText的密碼隱藏 
password.setTransformationMethod(PasswordTransformationMethod 
.getInstance()); 
} 
} 
} 

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

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

相關(guān)文章

最新評(píng)論

武胜县| 博白县| 梓潼县| 兴隆县| 太仆寺旗| 安阳县| 遂昌县| 通江县| 崇明县| 嘉禾县| 四子王旗| 贵南县| 巴林右旗| 霞浦县| 浮山县| 内丘县| 右玉县| 灌南县| 克山县| 墨竹工卡县| 南郑县| 广平县| 金昌市| 沙雅县| 定西市| 河曲县| 马关县| 炎陵县| 建昌县| 江城| 渝中区| 韶山市| 宕昌县| 浦县| 新绛县| 孝昌县| 多伦县| 利津县| 平罗县| 仪征市| 信阳市|