您的位置:首页 > 移动开发 > Android开发

Android 客户端登录界面实现

2013-09-03 19:25 585 查看
本文简单实现常用客户登录界面,如qq,微薄等客户端登录。

短暂停留界面:



登录界面:



实现比较简单,首先是短暂停留界面布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width ="fill_parent"
android:layout_height ="fill_parent"
android:scaleType ="fitXY"
android:src ="@drawable/splash" />
</LinearLayout>
该界面对应的Activity:

/**
* 应用启动短暂停留界面
* @author builder
*
*/
public class SplashActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent=new Intent(SplashActivity.this,LoginActivity.class);
startActivity(intent);
SplashActivity.this.finish();//结束本Activity
}
}, 1000);//设置执行时间
}
}
登录界面布局:

<RelativeLayout xmlns: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">
<ImageView
android:id ="@+id/loginbutton"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerHorizontal ="true"
android:layout_marginTop ="50dp"/>
<LinearLayout
android:id ="@+id/input"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_below ="@id/loginbutton"
android:layout_marginLeft ="28.0dip"
android:layout_marginRight ="28.0dip"
android:orientation ="vertical" >
<LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="44.0dip"
android:gravity ="center_vertical"
android:orientation ="horizontal" >
<EditText
android:id ="@+id/searchEditText"
android:layout_width ="0dp"
android:layout_height ="fill_parent"
android:layout_weight ="1"
android:background ="@null"
android:ems ="10"
android:hint="输入帐号"
android:imeOptions ="actionDone"
android:singleLine ="true"
android:textSize ="16sp" >
<requestFocus />
</EditText>
<Button
android:id ="@+id/button_clear"
android:layout_width ="20dip"
android:layout_height ="20dip"
android:layout_marginRight ="8dip"
android:visibility ="visible" />
</LinearLayout>
<View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:layout_marginLeft ="1.0px"
android:layout_marginRight ="1.0px"
android:background ="#ffc0c3c4" />
<EditText
android:id ="@+id/password"
android:layout_width ="fill_parent"
android:layout_height ="44.0dip"
android:gravity ="center_vertical"
android:background ="#00ffffff"
android:inputType ="textPassword"
android:hint="输入密码"
android:maxLength ="16"
android:maxLines ="1"
android:textColorHint ="#ff666666"
android:textSize ="16.0sp" />
</LinearLayout >
<Button
android:id ="@+id/buton1"
android:layout_width ="270dp"
android:paddingTop ="5.0dip"
android:layout_height ="50dp"
android:layout_marginLeft ="28.0dip"
android:layout_marginRight ="28.0dip"
android:layout_marginTop ="12.0dip"
android:layout_below ="@+id/input"
android:gravity ="center"
android:textSize ="20dp"
android:text = "登录" />

<RelativeLayout
android:id ="@+id/relative"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_alignLeft ="@+id/input"
android:layout_alignRight ="@+id/input"
android:layout_below ="@id/buton1" >
<CheckBox
android:id ="@+id/auto_save_password"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_alignParentLeft ="true"
android:background ="@null"
android:drawableLeft="@drawable/cpasswd"
android:button ="@null"
android:checked ="true"
android:drawablePadding ="4.0dip"
android:text = "记住密码"
android:textSize ="12.0sp" />
<Button
android:id ="@+id/regist"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_alignParentRight ="true"
android:clickable ="true"
android:gravity ="left|center"
android:paddingLeft ="8.0dip"
android:paddingRight ="18.0dip"
android:text = "注册新账号"
android:textSize ="12.0sp" />
</RelativeLayout >
<LinearLayout
android:id ="@+id/more_bottom"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_alignParentBottom ="true"
android:orientation ="vertical" >
<RelativeLayout
android:id ="@+id/input2"
android:layout_width ="fill_parent"
android:layout_height ="40dp"
android:orientation ="vertical" >
<ImageView
android:id ="@+id/more_image"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerVertical ="true"
android:layout_marginRight ="5.0dip"
android:layout_toLeftOf ="@+id/more_text"
android:clickable ="false"/>
<TextView
android:id ="@+id/more_text"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerInParent ="true"
android:background ="@null"
android:gravity ="center"
android:maxLines ="1"
android:text = "更多登陆选项"
android:textSize ="14.0sp" />
</RelativeLayout >
<LinearLayout
android:id ="@+id/morehidebottom"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:orientation ="vertical"
android:visibility ="gone" >

<View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:background ="#ff005484" />

<View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:background ="#ff0883cb" />

<LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_marginLeft ="30.0dip"
android:layout_marginRight ="30.0dip"
android:layout_marginTop ="12.0dip"
android:orientation ="horizontal" >
<CheckBox
android:id ="@+id/hide_login"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:layout_weight ="2.0"
android:background ="@null"
android:drawableLeft="@drawable/checkbox"
android:button ="@null"
android:checked ="false"
android:drawablePadding ="4.0dip"
android:text = "隐身登陆"
android:textSize ="12.0sp" />
<CheckBox
android:id ="@+id/silence_login"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:drawableLeft="@drawable/checkbox"
android:layout_weight ="1.0"
android:background ="@null"
android:button ="@null"
android:checked ="false"
android:drawablePadding ="4.0dip"
android:text = "静音登录"
android:textSize ="12.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_marginBottom ="18.0dip"
android:layout_marginLeft ="30.0dip"
android:layout_marginRight ="30.0dip"
android:layout_marginTop ="18.0dip"
android:orientation ="horizontal" >
<CheckBox
android:id ="@+id/accept_accounts"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:drawableLeft="@drawable/checkbox"
android:layout_weight ="2.0"
android:background ="@null"
android:button ="@null"
android:checked ="true"
android:drawablePadding ="4.0dip"
android:singleLine ="true"
android:text = "允许手机/电脑同时在心线"
android:textSize ="12.0sp" />
<CheckBox
android:id ="@+id/accept_troopmsg"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:drawableLeft="@drawable/checkbox"
android:layout_weight ="1.0"
android:background ="@null"
android:button ="@null"
android:checked ="true"
android:drawablePadding ="4.0dip"
android:text = "接受群消息"
android:textSize ="12.0sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout >
</RelativeLayout>
登录界面对应的Activity:

public class LoginActivity extends Activity implements OnClickListener {

private Button login_Button;
private View moreHideBottomView, input2;
private ImageView more_imageView;
private boolean mShowBottom = false;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}

private void initView() {
login_Button = (Button) findViewById(R.id.buton1);
login_Button.setOnClickListener(this);
moreHideBottomView = findViewById(R.id.morehidebottom);
more_imageView = (ImageView) findViewById(R.id.more_image);

input2 = findViewById(R.id.input2);
input2.setOnClickListener(this);
}

public void showBottom(boolean bShow) {
if (bShow) {
moreHideBottomView.setVisibility(View.GONE);
//more_imageView.setImageResource(R.drawable.login_more_up);
mShowBottom = true;
} else {
moreHideBottomView.setVisibility(View.VISIBLE);
//more_imageView.setImageResource(R.drawable.login_more);
mShowBottom = false;
}
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.input2:
showBottom(!mShowBottom);
break;
case R.id.buton1:
break;
default:
break;
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.activity_qq, menu);
return true;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: