栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android实现注册登录界面的实例代码

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android实现注册登录界面的实例代码

本文讲述了在linux命令下导出导入.sql文件的方法。分享给大家供大家参考,具体如下:

AndroidManifest.xml

 
 
  
  
   
   
   
   
  
  
   
   
   
  
  
   
   
   
  
  
 

MainActivity.java

package online.geekgalaxy.layoutlearn; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.support.v7.app.alertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
public class MainActivity extends AppCompatActivity { 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 //login button 
 final Button login = (Button) findViewById(R.id.button); 
 final String user = "admin"; 
 final String pass = "hello"; 
 
 login.setonClickListener(new View.onClickListener() { 
  public void onClick(View view) { 
  String username = ""; 
  EditText editText1 = (EditText)findViewById(R.id.editText); 
  username = editText1.getText().toString(); 
  String password = ""; 
  EditText editText2 = (EditText)findViewById(R.id.editText2); 
  password = editText2.getText().toString(); 
  if (username.equals(user) & password.equals(pass)) { 
   Intent intent = new Intent(MainActivity.this, login.class); 
   startActivity(intent); 
  } 
  else { 
   new alertDialog.Builder(MainActivity.this).setTitle("Error!").setMessage("Wrong username or password.") 
    .setNegativeButton("OK",null) 
    .show(); 
  } 
  } 
 }); 
 //register button 
 final Button register = (Button) findViewById(R.id.button2); 
 register.setonClickListener(new View.onClickListener() { 
  public void onClick(View view) { 
  //提示框确定是否跳转 
  new alertDialog.Builder(MainActivity.this).setTitle("Jump").setMessage("Ready to jump?") 
   .setPositiveButton("Yes", new DialogInterface.onClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
    Intent intent = new Intent(MainActivity.this, register.class); 
    startActivity(intent); 
    }}) 
   .setNegativeButton("No",null) 
   .show(); 
  } 
 }); 
 } 
} 

login.java

package online.geekgalaxy.layoutlearn; 
import android.app.Activity; 
import android.os.Bundle; 
 
public class login extends Activity { 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.login); 
 } 
} 

register.java

package online.geekgalaxy.layoutlearn; 
import android.app.Activity; 
import android.os.Bundle; 
 
public class register extends Activity{ 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.register); 
 } 
} 

activity_main.xml

 
 
 

login.xml

 
 
  
 

register.xml

 
 
  
  
  
  
  
 

strings.xml

 
 LayoutLearn 
 Login 
 Register 
 Username 
 Password 
 Great, you've logged in! 
 

build.gradle

apply plugin: 'com.android.application' 
android { 
 compileSdkVersion 25 
 buildToolsVersion "25.0.3" 
 defaultConfig { 
 applicationId "online.geekgalaxy.layoutlearn" 
 minSdkVersion 19 
 targetSdkVersion 25 
 versionCode 1 
 versionName "1.0" 
 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
 } 
 buildTypes { 
 release { 
  minifyEnabled false 
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
 } 
 } 
} 
dependencies { 
 compile fileTree(dir: 'libs', include: ['*.jar']) 
 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
 exclude group: 'com.android.support', module: 'support-annotations' 
 }) 
 compile 'com.android.support:appcompat-v7:25.3.1' 
 compile 'com.android.support.constraint:constraint-layout:1.0.2' 
 testCompile 'junit:junit:4.12' 
} 






转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/156194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号