效果:

1.点击图标进入页面二

2.页面2图片暂停显示5秒进入页面三

3.点击页面三登陆按钮,打开登陆对话框,输入密码进入页面四

点击下载按钮,显示水平进度条

8007e244840e3a56468b346e6465a4dc.png

be3c43f670c13c4c0e1c263bfdc54860.png

92d8a6beee43c5457f01da8d6876718a.png

34e87449972f1be7869ddb6557f8c6f0.png

2bbc3056398fb27274696458ade3cc70.png

18256d3371fde373bca4f528bce86147.png

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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐