Android——用对话框做登陆界面

效果:

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-08-01 23:44:43

Android——用对话框做登陆界面的相关文章

android——利用SharedPreference做引导界面

很久以前就接触过sharedPreference这个android中的存储介质.但是一直没有实际使用过,今天在看之前做的“民用机型大全”的app时,突然想到可以使用sharedPreference类来改进这个app中的一个缺陷. 此前,我先介绍sharedPreference的使用.Android数据总共有四种存储的方式 一.SharePreference 二.SQLite 三.File 四.ContentProvider SharedPreference类是一个轻量级的存储类,特别适合保存软件

c#做登陆界面

登陆界面最主要的就是数据库访问,这里就不多讲界面设计了, 直接给代码:(这段代码加在登陆按钮的事件里) #region 定义用户信息变量 string UserName = TextBox_User_Name.Text.Trim(); string UserPassword = TextBox_User_Password.Text.Trim(); #endregion #region 检查用户是否输入用户信息 if (UserName == "" && UserPass

Android学习笔记(4)——登陆界面模拟及存储文件到内存

搬运自本人博客:xge技术博客 原文:http://www.xgezhang.com/android_login_save_file.html 在本机或服务器上保存文件是比较简单的一件事,那么在安卓系统下我们该如何存储文件呢?这里我们借用登陆界面常见的"记住登陆用户名密码"的为例,来介绍一下如何把文件保存到手机内存,也综合复习和练习一下之前的内容: 首先我们还是先做界面: 对应的xml布局文件如下,采用的是线性布局加上相对布局来实现的: ? 1 2 3 4 5 6 7 8 9 10 1

Android学习笔记(二)--iparty登陆界面

打开应用,判断是否第一次使用. 1 private void beforeInitMenu() { 2 AppContext appContext = (AppContext) getApplicationContext(); 3 4 if (appContext.isFirstLogin()) { 5 // 第一次启动 6 //如果第一次启动,出现5张引导图片. 7 Intent intent = new Intent(this, GuideActivity.class); 8 startAc

Android登陆界面实现-支持输入框清楚和震动效果功能

演示效果 主要代码如下 自定义的一个EditText,用于实现有文字的时候显示可以清楚的按钮: import android.content.Context; import android.graphics.drawable.Drawable; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.MotionEven

Android的弹出登陆框的实现

最近在做一个项目,要用到登陆框,几经波折,最后用的是直接将Activity的Theme属性设置成Dialog,然后达到了我想要的效果. 下面是我的实现经历: 1.首先,我是直接使用AlertDialog来实现,确定是,形状有点难看,而且获得Dialog里面的控件略显麻烦(因为我要做的登陆框有一定的布局),然后就给我就放弃了,可能因为我太水了,不能很好的使用它 2.然后我就使用PopupWindow来实现,界面是达到了我的要求,控件的获得通过Inflater就可以获得了相对较简单,但是有一个缺点就

【转】【Android】对话框 AlertDialog -- 不错不错

原文网址:http://blog.csdn.net/feng88724/article/details/6171450 本讲介绍一下Android基本组件:对话框AlertDialog. API: java.lang.Object    ? android.app.AlertDialog.Builder 使用AlertDialog.Builder创建对话框需要了解以下几个方法: setTitle :为对话框设置标题 setIcon :为对话框设置图标 setMessage:为对话框设置内容 se

alertDialog创建登陆界面,判断用户输入

alertDialog创建登陆界面,需要获取用户输入的用户名和密码,获取控件对象的时候不能像主布局文件那样获得, 需要在onClickListener中获取,代码如下: 1 public boolean onOptionsItemSelected(MenuItem item) { 2 // TODO Auto-generated method stub 3 switch(item.getItemId()){ 4 case 1: 5 Intent intent = new Intent(); 6

项目前安装软件以及登陆界面(Eclipse+JDK+SDK+ADT )

 我们准备做的是一个聊天软件,所以我尝试做了一下登陆界面.本来打算用前段的技术实现,后来就做了一下子,但是没有完善.上周刚好买了本安卓的书,于是自学了一部分知识.于是自己尝试做下手机端的登陆界面. 进行安卓开发,首先是安装软件:Eclipse+JDK+SDK+ADT(虽然Android studio现在非常流行,但是我还是用eclipse配置了,感觉用习惯了eclipse) 可以直接在这里下载所有的软件:http://www.android-studio.org/ 为什么不直接进官网下载?由于某