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

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

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

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

廢話不多說,先上效果圖了,如果大家感覺還不錯,請參考實現(xià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="注冊" 
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: 
// 注冊按鈕 
Toast.makeText(MainActivity.this, "注冊", 0).show(); 
break; 
case R.id.forgive_pwd: 
// 忘記密碼按鈕 
Toast.makeText(MainActivity.this, "忘記密碼", 0).show(); 
break; 
default: 
break; 
} 
} 
/** 
* 密碼可見與不可見的切換 
* 
* @param flag 
*/ 
private void changePwdOpenOrClose(boolean flag) { 
// 第一次過來是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,就是這么簡單,效果完成。

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

相關(guān)文章

最新評論

定日县| 洱源县| 义乌市| 昌江| 本溪| 金溪县| 镇安县| 张北县| 海宁市| 乐平市| 资中县| 方城县| 上饶县| 淮南市| 石楼县| 玉门市| 电白县| 拜泉县| 金山区| 新营市| 高州市| 托克托县| 闵行区| 和龙市| 金塔县| 紫阳县| 平度市| 珲春市| 长沙市| 营口市| 于田县| 顺昌县| 贵定县| 隆尧县| 原阳县| 呼图壁县| 临湘市| 会泽县| 万全县| 罗山县| 元阳县|