‘壹’ 如何设计android的登录界面
在网上在到一个登录界面感觉挺不错的,给大家分享一下~先看效果图:
这个Demo除了按钮、小猫和Logo是图片素材之外,其余的UI都是通过代码实现的。
?
一、背景
背景蓝色渐变,是通过一个xml文件来设置的。代码如下:
background_login.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:andro>
<gradient
android:startColor="#FFACDAE5"
android:endColor="#FF72CAE1"
android:angle="45"
/>
</shape>
startColor是渐变开始的颜色值,endColor是渐变结束的颜色值,angle是渐变的角度。其中#FFACDAE5中,FF是Alpha值,AC是RGB的R值,DA是RGB的G值,E5是RGB的B值,每个值在00~FF取值,即透明度、红、绿、蓝有0~255的分值,像要设置具体的颜色,可以在PS上的取色器上查看设置。
?
?
二、圆角白框
效果图上面的并不是白框,其实框是白色的,只是设置了透明值,也是靠一个xml文件实现的。
background_login_div.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:andro>
<solid android:color="#55FFFFFF" />
<!-- 设置圆角
注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角-->
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/>
</shape>
?
三、界面的布局
界面的布局挺简单的,就直接贴代码啦~
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:andro
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:
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:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="@string/login_label_username"
/>
<EditText
android:
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"/>
<!-- 密码 text -->
<TextView
android:
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"
/>
<EditText
android:
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 -->
<Button
android:
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>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView android:
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:
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"/>
</RelativeLayout>
</LinearLayout>
‘贰’ android 登陆页面用什么启动模式
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作。在Android中Activity的启动模式决定了Activity的启动运行方式。
Android总Activity的启动模式分为四种:
Activity启动模式设置:
<activity android:name=".MainActivity" android:launchMode="standard" />
Activity的四种启动模式:
1. standard
模式启动模式,每次激活Activity时都会创建Activity,并放入任务栈中。
2. singleTop
如果在任务的栈顶正好存在该Activity的实例, 就重用该实例,否者就会创建新的实例并放入栈顶(即使栈中已经存在该Activity实例,只要不在栈顶,都会创建实例)。
3. singleTask
如果在栈中已经有该Activity的实例,就重用该实例(会调用实例的onNewIntent())。重用时,会让该实例回到栈顶,因此在它上面的实例将会被移除栈。如果栈中不存在该实例,将会创建新的实例放入栈中。
4. singleInstance
在一个新栈中创建该Activity实例,并让多个应用共享改栈中的该Activity实例。一旦改模式的Activity的实例存在于某个栈中,任何应用再激活改Activity时都会重用该栈中的实例,其效果相当于多个应用程序共享一个应用,不管谁激活该Activity都会进入同一个应用中。
其中standard是系统默认的启动模式。
下面通过实例来演示standard的运行机制:
1 private TextView text_show;
2 private Button btn_mode;
3
4 @Override
5 public void onCreate(Bundle savedInstanceState) {
6 super.onCreate(savedInstanceState);
7 setContentView(R.layout.activity_main);
8
9 text_show = (TextView) this.findViewById(R.id.text_show);
10
11 text_show.setText(this.toString());
12
13 btn_mode = (Button) this.findViewById(R.id.btn_mode);
14
15 }
16
//按钮单击事件
17 public void LaunchStandard(View v){
18 startActivity(new Intent(this,MainActivity.class));
19
20 text_show.setText(this.toString());
21 }
‘叁’ android怎么做动态的登陆界面
设计android的登录界面的方法:
UI实现的代码如下:
1、背景设置图片:
background_login.xml
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFACDAE5"
android:endColor="#FF72CAE1"
android:angle="45"
/>
</shape>
2、圆角白框
效果图上面的并不是白框,其实框是白色的,只是设置了透明值,也是靠一个xml文件实现的。
background_login_div.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">
<solidandroid:color="#55FFFFFF"/>
<!--设置圆角
注意:bottomRightRadius是左下角而不是右下角bottomLeftRadius右下角-->
<cornersandroid:topLeftRadius="10dp"android:topRightRadius="10dp"
android:bottomRightRadius="10dp"android:bottomLeftRadius="10dp"/>
</shape>
3、界面布局:
login.xml
<?xmlversion="1.0"encoding="utf-8"?>
<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"/>
<!--密码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-->
<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>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextViewandroid: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"/>
<ImageViewandroid: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"/>
<ImageViewandroid: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"/>
</RelativeLayout>
</LinearLayout>
4、java源代码,Java源文件比较简单,只是实例化Activity,去掉标题栏。
packagecom.mytwitter.acitivity;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Window;
{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
}
}
5、实现效果如下:
‘肆’ 如何使用Android Studio开发用户登录界面
右键点击new-->Mole,Mole相当于新建了一个项目;
选择Android Application,点击next
将My Mole 和app改成自己项目相应的名字,同时选择支持的Android版本
这一步我们选择Blank Activity,自己手动编写登录界面,而不依赖系统内置的Login Activity,一直点击next,最后点击finish就完成了项目的创建
在project下我们可以看到出现了我们刚才创建的login项目
展开res/layout,点击打开activity_main.xml文件,在这个文件里我们将完成登录界面的编写
进行登录页面的编写
‘伍’ 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)模式有关。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<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/images1"
>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_weight="0.9"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/LinearLayout02"
android:layout_weight="0.1"
android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout03" android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
<LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:id="@+id/LinearLayout_account"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView android:textSize="12pt" android:id="@+id/lblAccount"
android:text="@string/accountName"
android:layout_weight="0.75"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
<EditText
android:layout_weight="0.25"
android:layout_width="fill_parent"
android:text="mailto:%22 %20android:id=%22@+id/editBoxAccount" android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView android:textSize="12pt" android:id="@+id/lblPassword"
android:text="@string/password"
android:layout_weight="0.75"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
<EditText
android:layout_weight="0.25"
android:layout_width="fill_parent"
android:password="true"
android:text="mailto:%22 %20android:id=%22@+id/editBoxPassword" android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<Button android:text="登录"
android:textSize="9pt"
android:id="@+id/btnLogin" android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
‘陆’ android登录界面
用户和密码前面的图标 可以使用android:drawLeft
“登录”是定义一个TextView, 设置android:text属性,“前面的箭头”找美工做图片
‘柒’ 如何用android项目开发qq邮箱网页版登录界面
你是要在手机上实现QQ邮箱网页版登录还是仿那个邮箱登录界面做个UI?
如果是直接加载QQ邮箱网页版登录界面的话,之前楼上答的很正确,用webview加载URL,顶多做点界面适配,让网页适配手机大小,字体大小做点设置什么的
如果是仿UI,让美工切图,自己写一下布局就可以了,具体登录逻辑估计要配合后端服务才能形成一整套系统
‘捌’ 怎么用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<A class=keylink href="http://www.it165.net/e/ebg/" target=_blank>word</A> = "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<A class=keylink href="http://www.it165.net/e/ebg/" target=_blank>word</A>, 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<User> 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<User> getUserList(Context context) {
49. /* 加载 */
50. FileInputStream in = null;
51. ArrayList<User> users = new ArrayList<User>();
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 Studio开发用户登录界面
android的界面一般 都是通过布局文件进行页面编写然后代码实现控件绑定,实现登录功能。无论还是androidstudio 还是eclipse 都是这样。