效果:
1.点击图标进入页面二
2.页面2图片暂停显示5秒进入页面三
3.点击页面三登陆按钮,打开登陆对话框,输入密码进入页面四
点击下载按钮,显示水平进度条
MainActivity.java
package com.example.chenshuai.test404; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onclick(View view) { Intent intent = new Intent(this,Activity1.class); startActivity(intent); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.chenshuai.test404.MainActivity"> <ImageButton android:layout_width="90dp" android:layout_height="90dp" android:src="@drawable/logo" android:onClick="onclick"/> </RelativeLayout>
Activity1.java
package com.example.chenshuai.test404; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import java.util.Timer; import java.util.TimerTask; /** * Created by chenshuai on 2016/4/3. */ public class Activity1 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity1_layout); //图片暂停5秒后显示 final Intent it = new Intent(this, Activity2.class); //你要转向的Activity Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { startActivity(it); //执行 } }; timer.schedule(task, 1000 * 5); //5秒后 } }
activity1_layout.xml
<?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"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/denglu"/> </LinearLayout>
Activity2.java
package com.example.chenshuai.test404; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; import android.widget.Toast; /** * Created by chenshuai on 2016/4/3. */ public class Activity2 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity2_layout); } public void onclik1(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("登陆", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { 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 void onclick2(View v) { final ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMessage("下载进度"); pd.show(); //创建thread实例 重写run方法 启动多线程 new Thread() { @Override public void run() { 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
<?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"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/anniu1" android:text="点击登陆" android:textSize="20dp" android:onClick="onclik1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/anniu2" android:text="点击下载文件" android:textSize="20dp" android:onClick="onclick2" /> </LinearLayout>
login_layout.xml
<?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="90dp" android:layout_height="90dp" android:src="@drawable/touxiang" android:layout_marginTop="100dp" android:layout_gravity="center_horizontal"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="15275969278" android:textSize="20dp" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" /> <EditText android:layout_width="350dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:hint="请填写密码" android:inputType="textPassword" android:drawableLeft="@drawable/suo1" android:layout_marginTop="20dp" android:id="@+id/pwd" /> </LinearLayout>
Activity3.java
package com.example.chenshuai.test404; import android.app.Activity; import android.os.Bundle; /** * Created by chenshuai on 2016/4/4. */ public class Activity3 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity3_layout); } }
activity3_layout.xml
<?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"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/yemian"/> </LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.chenshuai.test404"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Activity1"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".Activity2"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".Activity3"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest>
时间: 2024-10-01 07:45:03