android 登陆对话框,Android——用对话框做登陆界面
效果:1.点击图标进入页面二2.页面2图片暂停显示5秒进入页面三3.点击页面三登陆按钮,打开登陆对话框,输入密码进入页面四点击下载按钮,显示水平进度条MainActivity.javapackagecom.example.chenshuai.test404;importandroid.content.Intent;importandroid.support.v7.app.AppCompatActi
效果:
1.点击图标进入页面二
2.页面2图片暂停显示5秒进入页面三
3.点击页面三登陆按钮,打开登陆对话框,输入密码进入页面四
点击下载按钮,显示水平进度条
MainActivity.java
packagecom.example.chenshuai.test404;importandroid.content.Intent;importandroid.support.v7.app.AppCompatActivity;importandroid.os.Bundle;importandroid.view.View;public class MainActivity extendsAppCompatActivity {
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}public voidonclick(View view)
{
Intent intent= new Intent(this,Activity1.class);
startActivity(intent);
}
}
activity_main.xml
Activity1.java
packagecom.example.chenshuai.test404;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importjava.util.Timer;importjava.util.TimerTask;/*** Created by chenshuai on 2016/4/3.*/
public class Activity1 extendsAppCompatActivity {
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity1_layout);//图片暂停5秒后显示
final Intent it = new Intent(this, Activity2.class); //你要转向的Activity
Timer timer = newTimer();
TimerTask task= newTimerTask() {
@Overridepublic voidrun() {
startActivity(it);//执行
}
};
timer.schedule(task,1000 * 5); //5秒后
}
}
activity1_layout.xml
Activity2.java
packagecom.example.chenshuai.test404;importandroid.app.AlertDialog;importandroid.app.ProgressDialog;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.widget.EditText;importandroid.widget.Toast;/*** Created by chenshuai on 2016/4/3.*/
public class Activity2 extendsAppCompatActivity {
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity2_layout);
}public voidonclik1(View view)
{//获取加载器
LayoutInflater layoutInflater =getLayoutInflater();//加载layout文件
View vi_1 = layoutInflater.inflate(R.layout.login_layout,null);//添加按钮
new AlertDialog.Builder(this)
.setView(vi_1)
.setNegativeButton("取消", null)
.setPositiveButton("登陆", newDialogInterface.OnClickListener() {
@Overridepublic void onClick(DialogInterface dialog, intwhich) {
AlertDialog al=(AlertDialog) dialog;
EditText pwd=(EditText) al.findViewById(R.id.pwd);
String str=pwd.getText().toString();if (str.equals("123")) {
Intent intent= new Intent(Activity2.this, Activity3.class);
startActivity(intent);
}else{
Toast.makeText(Activity2.this, "密码错误!", Toast.LENGTH_SHORT).show();
}
}
})
.show();
}public voidonclick2(View v)
{final ProgressDialog pd = new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMessage("下载进度");
pd.show();//创建thread实例 重写run方法 启动多线程
newThread()
{
@Overridepublic voidrun() {super.run();for (int i = 0;i<=pd.getMax();i++)
{try{
Thread.sleep(100);
}catch(Exception e)
{}
pd.setProgress(i);
}
pd.dismiss();
}
}.start();
}
}
activity2_layout.xml
/>
/>
login_layout.xml
/>
/>
Activity3.java
packagecom.example.chenshuai.test404;importandroid.app.Activity;importandroid.os.Bundle;/*** Created by chenshuai on 2016/4/4.*/
public class Activity3 extendsActivity {
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity3_layout);
}
}
activity3_layout.xml
AndroidManifest.xml
原文:http://www.cnblogs.com/Chenshuai7/p/5352066.html
更多推荐
所有评论(0)