Android_数据管理系统登陆界面设计及代码
layout:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
android:paddingBottom="50dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="50dp" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TableRow>
<TextView
android:id="@+id/txt_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/label_id"
android:textColor="@color/word" />
<EditText
android:id="@+id/edt_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:bufferType="editable"
android:inputType="none"
android:singleLine="true" >
<requestFocus />
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/txt_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_pass"
android:textColor="@color/word" />
<EditText
android:id="@+id/edt_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:inputType="textPassword"
android:singleLine="true" >
</EditText>
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/label_login" />
<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/label_clear" />
</LinearLayout>
</LinearLayout>
layout-land:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
android:paddingBottom="50dp"
android:paddingLeft="100dp"
android:paddingRight="100dp"
android:paddingTop="50dp" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TableRow>
<TextView
android:id="@+id/txt_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/label_id"
android:textColor="@color/word" />
<EditText
android:id="@+id/edt_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:bufferType="editable"
android:inputType="none"
android:singleLine="true" >
<requestFocus />
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/txt_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_pass"
android:textColor="@color/word" />
<EditText
android:id="@+id/edt_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:inputType="textPassword"
android:singleLine="true" >
</EditText>
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="50dp"
android:paddingRight="50dp" >
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/label_login" />
<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/label_clear" />
</LinearLayout>
</LinearLayout>
values:colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#abc</color>
<color name="word">#ff000000</color>
</resources>
values:strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, LoginActivity!</string>
<string name="app_name">数据管理系统</string>
<string name="label_id">工号</string>
<string name="label_pass">密码</string>
<string name="label_hint_id">在此输入工号</string>
<string name="label_hint_pass">在此输入密码</string>
<string name="label_login">登陆</string>
<string name="label_clear">清空</string>
</resources>
LoginActivity.java
package tomy.test.dms;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn_login = (Button) findViewById(R.id.btn_login);
//登陆
btn_login.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String s_edt_id = ((EditText)findViewById(R.id.edt_id)).getText().toString();
String s_edt_pass = ((EditText)findViewById(R.id.edt_pass)).getText().toString();
if(s_edt_id.length()<1 || s_edt_pass.length()<1)
{
//Toast.makeText(getApplicationContext(), "请先输入工号和密码!",Toast.LENGTH_SHORT).show();
if(s_edt_id.length()<1)
{
EditText eText=(EditText)findViewById(R.id.edt_id);
eText.setHint(R.string.label_hint_id);
}
if(s_edt_pass.length()<1)
{
EditText eText=(EditText)findViewById(R.id.edt_pass);
eText.setHint(R.string.label_hint_pass);
}
}
else
{
String toast_success = "登陆成功!";
Toast.makeText(getApplicationContext(), toast_success, Toast.LENGTH_SHORT).show();
String toast = "你输入的用户名是:" + s_edt_id + "密码是:" + s_edt_pass;
Toast.makeText(getApplicationContext(), toast,Toast.LENGTH_LONG).show();
}
}
});
//清空编辑框
Button btn_clear = (Button) findViewById(R.id.btn_clear);
btn_clear.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
EditText edt_id = (EditText) findViewById(R.id.edt_id);
EditText edt_pass = (EditText) findViewById(R.id.edt_pass);
edt_id.setHint(null);
edt_pass.setHint(null);
edt_id.setText(null);
edt_pass.setText(null);
edt_id.requestFocus();
}
});
}
}

浙公网安备 33010602011771号