安卓登录界面代码,android怎么做动态的登陆界面
安卓登录界面代码,android怎么做动态的登陆界面详细介绍
本文目录一览: 怎么用android写登录界面
主要的代码:
1、用户类User
view sourceprint?
01.package com.example.logindemo;
02.
03.import org.json.JSONException;
04.import org.json.JSONObject;
05.import android.util.Log;
06.
07.public class User {
08. private String mId;
09. private String mPwd;
10. private static final String masterPass = "FORYOU"; // AES加密算法的种子
11. private static final String JSON_ID = "user_id";
12. private static final String JSON_PWD = "user_pwd";
13. private static final String TAG = "User";
14.
15. public User(String id, String pwd) {
16. this.mId = id;
17. this.mPwd = pwd;
18. }
19.
20. public User(JSONObject json) throws Exception {
21. if (json.has(JSON_ID)) {
22. String id = json.getString(JSON_ID);
23. String pwd = json.getString(JSON_PWD);
24. // 解密后存放
25. mId = AESUtils.decrypt(masterPass, id);
26. mPwd = AESUtils.decrypt(masterPassword, pwd);
27. }
28. }
29.
30. public JSONObject toJSON() throws Exception {
31. // 使用AES加密算法加密后保存
32. String id = AESUtils.encrypt(masterPassword, mId);
33. String pwd = AESUtils.encrypt(masterPassword, mPwd);
34. Log.i(TAG, "加密后:" + id + " " + pwd);
35. JSONObject json = new JSONObject();
36. try {
37. json.put(JSON_ID, id);
38. json.put(JSON_PWD, pwd);
39. } catch (JSONException e) {
40. e.printStackTrace();
41. }
42. return json;
43. }
44.
45. public String getId() {
46. return mId;
47. }
48.
49. public String getPwd() {
50. return mPwd;
51. }
52.}
2、保存和加载本地User列表
view sourceprint?
01.package com.example.logindemo;
02.
03.import java.io.BufferedReader;
04.import java.io.FileInputStream;
05.import java.io.FileNotFoundException;
06.import java.io.IOException;
07.import java.io.InputStreamReader;
08.import java.io.OutputStream;
09.import java.io.OutputStreamWriter;
10.import java.io.Writer;
11.import java.util.ArrayList;
12.import org.json.JSONArray;
13.import org.json.JSONException;
14.import org.json.JSONTokener;
15.
16.import android.content.Context;
17.import android.util.Log;
18.
19.public class Utils {
20.
21. private static final String FILENAME = "userinfo.json"; // 用户保存文件名
22. private static final String TAG = "Utils";
23.
24. /* 保存用户登录信息列表 */
25. public static void saveUserList(Context context, ArrayList
users)
26. throws Exception {
27. /* 保存 */
28. Log.i(TAG, "正在保存");
29. Writer writer = null;
30. OutputStream out = null;
31. JSONArray array = new JSONArray();
32. for (User user : users) {
33. array.put(user.toJSON());
34. }
35. try {
36. out = context.openFileOutput(FILENAME, Context.MODE_PRIVATE); // 覆盖
37. writer = new OutputStreamWriter(out);
38. Log.i(TAG, "json的值:" + array.toString());
39. writer.write(array.toString());
40. } finally {
41. if (writer != null)
42. writer.close();
43. }
44.
45. }
46.
47. /* 获取用户登录信息列表 */
48. public static ArrayList
getUserList(Context context) {
49. /* 加载 */
50. FileInputStream in = null;
51. ArrayList
users = new ArrayList
();
52. try {
53.
54. in = context.openFileInput(FILENAME);
55. BufferedReader reader = new BufferedReader(
56. new InputStreamReader(in));
57. StringBuilder jsonString = new StringBuilder();
58. JSONArray jsonArray = new JSONArray();
59. String line;
60. while ((line = reader.readLine()) != null) {
61. jsonString.append(line);
62. }
63. Log.i(TAG, jsonString.toString());
64. jsonArray = (JSONArray) new JSONTokener(jsonString.toString())
65. .nextValue(); // 把字符串转换成JSONArray对象
66. for (int i = 0; i < jsonArray.length(); i++) {
67. User user = new User(jsonArray.getJSONObject(i));
68. users.add(user);
69. }
70.
71. } catch (FileNotFoundException e) {
72. e.printStackTrace();
73. } catch (IOException e) {
74. e.printStackTrace();
75. } catch (JSONException e) {
76. e.printStackTrace();
77. } catch (Exception e) {
78. e.printStackTrace();
79. }
80.
81. return users;
82. }
83.}
3、AES加密/解密
view sourceprint?
01.package com.example.logindemo;
02.
03.
04.import java.security.SecureRandom;
05.
06.import javax.crypto.Cipher;
07.import javax.crypto.KeyGenerator;
08.import javax.crypto.SecretKey;
09.import javax.crypto.spec.IvParameterSpec;
10.import javax.crypto.spec.SecretKeySpec;
11.
12.public class AESUtils {
13. public static String encrypt(String seed, String cleartext)
14. throws Exception {
15. byte[] rawKey = getRawKey(seed.getBytes());
16. byte[] result = encrypt(rawKey, cleartext.getBytes());
17. return toHex(result);
18. }
19.
20. public static String decrypt(String seed, String encrypted)
21. throws Exception {
22. byte[] rawKey = getRawKey(seed.getBytes());
23. byte[] enc = toByte(encrypted);
24. byte[] result = decrypt(rawKey, enc);
25. return new String(result);
26. }
27.
28. private static byte[] getRawKey(byte[] seed) throws Exception {
29. KeyGenerator kgen = KeyGenerator.getInstance("AES");
30. SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
31. sr.setSeed(seed);
32. kgen.init(128, sr);
33. SecretKey skey = kgen.generateKey();
34. byte[] raw = skey.getEncoded();
35. return raw;
36. }
37.
38. private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
39. SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
40. Cipher cipher = Cipher.getInstance("AES");
41. cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(
42. new byte[cipher.getBlockSize()]));
43. byte[] encrypted = cipher.doFinal(clear);
44. return encrypted;
45. }
46.
47. private static byte[] decrypt(byte[] raw, byte[] encrypted)
48. throws Exception {
49. SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
50. Cipher cipher = Cipher.getInstance("AES");
51. cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(
52. new byte[cipher.getBlockSize()]));
53. byte[] decrypted = cipher.doFinal(encrypted);
54. return decrypted;
55. }
56.
57. private static String toHex(String txt) {
58. return toHex(txt.getBytes());
59. }
60.
61. private static String fromHex(String hex) {
62. return new String(toByte(hex));
63. }
64.
65. private static byte[] toByte(String hexString) {
66. int len = hexString.length() / 2;
67. byte[] result = new byte[len];
68. for (int i = 0; i < len; i++)
69. result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2),
70. 16).byteValue();
71. return result;
72. }
73.
74. private static String toHex(byte[] buf) {
75. if (buf == null)
76. return "";
77. StringBuffer result = new StringBuffer(2 * buf.length);
78. for (int i = 0; i < buf.length; i++) {
79. appendHex(result, buf[i]);
80. }
81. return result.toString();
82. }
83.
84. private final static String HEX = "0123456789ABCDEF";
85.
86. private static void appendHex(StringBuffer sb, byte b) {
87. sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
88. }
89.}
android怎么做动态的登陆界面
设计android的登录界面的方法:
UI实现的代码如下:
1、背景设置图片:
background_login.xml
<gradient
android:startColor="#FFACDAE5"
android:endColor="#FF72CAE1"
android:angle="45"
/>
2、圆角白框
效果图上面的并不是白框,其实框是白色的,只是设置了透明值,也是靠一个xml文件实现的。
background_login_div.xml
<!-- 设置圆角
注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角-->
<corners android:topleftradius="10dp" android:toprightradius="10dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/>
3、界面布局:
login.xml
<linearlayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_login">
<!-- padding 内边距 layout_margin 外边距
android:layout_alignParentTop 布局的位置是否处于顶部 -->
<relativelayout
android:id="@+id/login_div"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dip"
android:layout_margin="15dip"
android:background="@drawable/background_login_div_bg" >
<textview
android:id="@+id/login_user_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="@string/login_label_username"
style="@style/normalText"/>
<edittext
android:id="@+id/username_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/login_username_hint"
android:layout_below="@id/login_user_input"
android:singleLine="true"
android:inputType="text"/>
<textview
android:id="@+id/login_password_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/username_edit"
android:layout_marginTop="3dp"
android:text="@string/login_label_password"
style="@style/normalText"/>
<edittext
android:id="@+id/password_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_password_input"
android:password="true"
android:singleLine="true"
android:inputType="textPassword" />
<button
android:id="@+id/signin_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/password_edit"
android:layout_alignRight="@id/password_edit"
android:text="@string/login_label_signin"
android:background="@drawable/blue_button" />
<relativelayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<textview android:id="@+id/register_link"
android:text="@string/login_register_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textColor="#888"
android:textColorLink="#FF0066CC" />
<imageview android:id="@+id/miniTwitter_logo"
android:src="@drawable/cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="25dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="25dp" />
<imageview android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/miniTwitter_logo"
android:layout_alignBottom="@id/miniTwitter_logo"
android:paddingBottom="8dp"/>
4、java源代码,Java源文件比较简单,只是实例化Activity,去掉标题栏。
package com.mytwitter.acitivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
}
}
5、实现效果如下:
如何使用Android Studio开发用户登录界面
这项目的前提是自己已经将基本的运行环境及sdk都已经安装好了,读者可自行百度环境配置相关内容,这里不再赘述。右键点击new-->Module,Module相当于新建了一个项目。
选择Android Application,点击next
将My Module 和app改成自己项目相应的名字,同时选择支持的Android版本
这一步选择Blank Activity,自己手动编写登录界面,而不依赖系统内置的Login Activity,一直点击next,最后点击finish就完成了项目的创建
在project下可以看到出现了刚才创建的login项目
展开res/layout,点击打开activity_main.xml文件,在这个文件里将完成登录界面的编写
这是初始的主界面,还没有经过自己编写的界面,Android Studio有一个很强大的预览功能,相当给力
将activity_main.xml的代码替换成如下代码:
<tablelayout xmlns:android="http。//schemas。android。com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:stretchColumns="0,3">
<textview
android:text="账 号:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
/>
<edittext
android:id="@+id/account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:minWidth="220px"/>
<textview
android:text="密 码:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<edittext
android:id="@+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="220px"
android:textSize="24px"
android:inputType="textPassword"/>
<button
android:id="@+id/login"
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<button
android:id="@+id/quit"
android:text="退出"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
使用Android 手机进行测试,大功告成
工具/原料
Android Studio
Android SDK
java jdk
一台可以用于调试的安卓手机
1.项目的前提是已经将基本的运行环境及sdk都已经安装好了。右键点击new-->Module,Module相当于新建了一个项目。如图所示
2.选择Android Application,点击next
3.将My Module 和app改成自己项目相应的名字,同时选择支持的Android版本
4.这一步选择Blank Activity,自己手动编写登录界面,而不依赖系统内置的Login Activity,一直点击next,最后点击finish就完成了项目的创建
5.在project下可以看到出现了刚才创建的login项目了
6.展开res/layout,点击打开activity_main.xml文件,在这个文件里我们将完成登录界面的编写
7.这是初始的主界面,还没有经过编写的界面,Android Studio有一个很强大的预览功能
8.将activity_main.xml的代码替换成如下代码:
<textview
9.预览效果如图
10.完成.
</button
</button
</edittext
</textview
</edittext
</textview
android开发登录界面怎么写
如果上图所示,就是简单的登录界面了。andord的布局真的是,真的是,哪个。难以掌握的东西,哈,不过一旦了解深入点,又让人爽的不行,流式布局总是比起windows mobile的绝对布局简单而且容易控制。我是越来越倾向于流式布局的方式了,它的一点好处是适应设备时比较灵巧,wm使用了自适应dpi的方式,哪叫一个复杂啊,切不易于控制。
布局的属性 android:layout_width="fill_parent" ,指示了填充父区域,就是父容器有多大空间,就填充多大空间。android:layout_width="wrap_content",指示了它本身需要多大空间,就像父容器索取多大的空间,怎么说呢,就是它有多胖就占多大空。而哪个fill_parent就是不胖也全占满了。 再说android:layout_weight="0.1",这个weight(重量)是个很有意思的东西。可为一个父容器的 “子控件们”设置这个重量属性,父容器根据这个重量的多少择情分给这些子控件们多大空间。同时这个属性还与子控件 宽高属性的显示(fill_parent 或者wrap_content)模式有关。
代码如下:
安卓开发软件欢迎界面怎么做
显示一个加载的界面,增加一个延时任务。比如用handler,几秒后再执行跳转到主界面。
安卓开发软件欢迎界面的代码如下:
1、制作一张启动图片splash.png,放置在res->drawable-hdpi文件夹中。
2、新建布局文件splash.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash" >
<textview
android:id="@+id/versionNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="26dp"
android:layout_marginRight="52dp"
android:text="version 1.0"
android:textColor="" />
这里我们把上一步制作的图片作为启动界面的背景图,然后在界面底部显示当前程序的版本号。
3、新建SplashActivity,在Oncreate中添加以下代码:
PackageManager pm = getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo("com.lyt.android", 0);
TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
versionNumber.setText("Version " + pi.versionName);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this,SplashScreenActivity.class);
startActivity(intent);
SplashActivity.this.finish();
}
}, 2500);
4、 修改Manifest文件,将启动界面Activity改为默认启动,并且设置标题栏不可见。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sinaweibo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<activity
android:name=".MainActivity1"
android:label="@string/title_activity_main_activity1" >
</activity
</activity
</application
</uses-sdk
这样打开应用后等待2.5秒就进入第二个activity MainActivity了。
</textview
用eclipse开发安卓应用,现在只做了个界面。请问在点击“登录”以后怎么跳转页面,代码怎么写,怎
在 onClick中写
Intent intent = new Intent(LoginActivity.this, HelloWorldActivity.class);
startActivity(intent);
假定你当前的类叫LoginActivity,要启动的叫HelloWorldActivity
安卓Android,我做了一个APP的开启界面,像QQ那种,先显示一个全屏的logo,过几秒再进入
Timer timer = new Timer(); TimerTask timertask = new TimerTask(){@Overridepublic void run() {// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this,???.class);startActivity(intent);MainActivity.this.finish();}};timer.schedule(timertask, 1000);//这个是我自己写一个安卓程序用的一段代码,先显示一个界面,1000ms后自动跳转
用java写一个手机商城注册界面代码
请描述好具体需求,你说的这个既可以用web实现,也可以是安卓实现
如果是说的jsp(web实现),就是连接数据库,然后简单写一下就好了,网上有很多这种源码的
安卓的话,就写一个页面然后连接本地的sqlite数据库就好了
这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。
在java的JFrame内通过创建匿名对象的方式做登录界面
package com.sxt;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame{
JTextField txtname=new JTextField();
JPasswordField txtpass=new JPasswordField();
JButton bl=new JButton("登录");
JButton bg=new JButton("关闭");
//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调
public LoginFrame(){
setBounds(25,25,250,250);
Container c = getContentPane();
c.setLayout(new GridLayout(4,2,10,10));
c.add(new JLabel("用户名"));
c.add(txtname);
c.add(new JLabel("密码"));
c.add(txtpass);
c.add(bl);
c.add(bg);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//注意:此处是匿名内部类
bg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
}
);
//注意:此处是匿名内部类
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
一次性代码安卓在哪里输入
安卓输入一次性代码的地方在拨号界面。
打开手机的拨号界面,使用拨号键盘输入代码即可。
代码一:
*#06#快速找到手机里面的IMEI码、MEID和SN码,那么在参加内测版本更新时,就能派上用场。IMEI码查询之后,如果上面的数字和手机背面贴的代码一致,说明手机就是正品。
代码二:
*#*#1357946#*#*查询手机序列号,可以知道手机的生产日期。一般序列号有16位数字。6、7位代表手机生产年份,8代表生产月份,9、10代表具体日期。
代码三:
*#*#2846579#*#*"查询"工程菜单",还能测试手机性能。包含功能:后台设置、单板信息查询、网络信息查询、软件升级、恢复出厂设置、补电。
代码四:
"*#*#6130#*#*"查询手机使用情况,你使用手机的每一个步骤都能进行查询。如使用手机的记录,包括使用过什么工具、时间等情况。
一次性代码的相关介绍
一次性代码是一种简单的认证方式,它可以帮助用户确认自己的身份,但是它本身并不能提供安全保护。一次性代码只能用于确认身份,而不能用于保护数据。要解决这个问题,可以采用多种安全措施,比如加密、认证、访问控制等。加密可以保护数据的安全性,认证可以确保只有授权的用户才能访问数据,而访问控制可以限制用户对数据的访问权限。
此外,还可以采用双因素认证,以确保用户的身份安全。双因素认证是一种安全技术,它要求用户提供两个不同的凭据,才能确认用户的身份。这两个凭据可以是一个密码和一个短信验证码,或者是一个密码和一个生物特征,比如指纹或虹膜识别。