五一三天假,实在是无聊,随便做了一下废话不多说:先给大家看一下效果图
下面直接上代码
布局文件
first_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@drawable/sea" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="倒计时..."
android:textColor="#8B0000"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.login.MainActivity"
android:background="#18881f"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="智能交通管理系统"
android:textColor="#000000"
android:textSize="35dp"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<TextView
android:text="用户名"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="25dp"
android:gravity="center"
android:layout_gravity="center"
/>
<EditText
android:id="@+id/yonghu"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:maxLength="8"
android:ems="8"
android:hint="请输入用户名"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="密码"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="25dp"
android:gravity="center"
/>
<EditText
android:id="@+id/password"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:maxLength="8"
android:ems="8"
android:hint="请输入密码"
android:inputType="textPassword"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"
android:textColor="#000000"
android:layout_gravity="center"
android:layout_marginRight="70dp"
android:textSize="15dp"/>
<RadioGroup
android:id="@+id/RadioGroup1"
android:layout_width ="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/RadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="是"
android:checked="true"
android:layout_marginRight="20dp"
android:gravity="center"
/>
<RadioButton
android:id="@+id/RadioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="否"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/zhuce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户注册 "
android:textColor="#000000"
android:layout_gravity="right"
android:layout_marginTop="30dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="忘记密码?"
android:textColor="#000000"
android:layout_gravity="right"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/qx"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="取消"
android:textSize="30dp"/>
<Button
android:id="@+id/buttonlogin"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="登录"
android:textSize="30dp"/>
<Button
android:id="@+id/cz"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="重置"
android:textSize="30dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/fuqi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="服务器地址设置"
/>
</LinearLayout>
</LinearLayout>
Java文件
FirstActivity.java
package com.example.jnds;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
public class FirstActivity extends Activity{
private Button button;
private int count =5;
private int COUNT_TIME = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_activity);
button = (Button) findViewById(R.id.button);
clickButton();
}
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(count <= 0){
count = 5;
button.setText("欢迎进入");
button.setClickable(true);
return;
}
count--;
button.setText("倒计时"+count);
sendEmptyMessageDelayed(COUNT_TIME,1000);//延时1秒将消息加入列队
}
};
public void clickButton(){
handler.sendEmptyMessage(COUNT_TIME);
button.setClickable(false);
handler.postDelayed(new Thread(){
public void run(){
Intent intent=new Intent(FirstActivity.this,Login.class);
startActivity(intent);
}
}, 5000);
}
}
Login.java
package com.example.jnds;
import javax.swing.JOptionPane;
import android.animation.AnimatorSet.Builder;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonlogin=(Button) findViewById(R.id.buttonlogin);
final EditText yonghu=(EditText) findViewById(R.id.yonghu);
final EditText password=(EditText) findViewById(R.id.password);
buttonlogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String jyonghu; String jpassword;
jyonghu=yonghu.getText().toString();
jpassword=password.getText().toString();
Log.e("dd", jyonghu +","+jpassword);
if(jyonghu.equals("1111")&&jpassword.equals("1111")){
Intent intent=new Intent(Login.this,Zhuce.class);
startActivity(intent);
}
else{
//JOptionPane.showMessageDialog(null, "标题【出错啦】", "年龄请输入数字", JOptionPane.ERROR_MESSAGE);
}
}
});
final TextView zhuce=(TextView) findViewById(R.id.zhuce);
zhuce.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent=new Intent();
intent.setClass(Login.this, Zhuce.class);
startActivity(intent);
}
});
TextView fuqi=(TextView) findViewById(R.id.fuqi);
fuqi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Log.e(" ss","ss");
finish();
Intent I=new Intent();
I.setClass(Login.this, Ip.class);
startActivity(I);
Log.e(" wees","ss");
}
});
final Button cz=(Button) findViewById(R.id.cz);
cz.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
password.setText(null);
//password.setText(password.getText()+"");
yonghu.setText(null);
}
});
final Button qc=(Button) findViewById(R.id.qx);
qc.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}