淘忆项目之欢迎界面的归纳分享
2016-08-22 13:28
155 查看
淘忆项目之欢迎界面的修正归纳
欢迎界面,简单明了的文字,突出app的主题加意义就可以了。
欢迎界面,第一个功能加入是否首次进入App的判定来表示欢迎界面之后是主界面还是引导界面,第二个功能是实现用户登录,这样加强用户的交互效果,让再次进入app的时候能够实现自动登录,避免用户多次登录的繁琐,第三个功能就是简单说明App的主旨。
第一:
用photoshop CC 2015.5绘制UI界面,并且用CutterMan截下图标背景等。
![](https://img-blog.csdn.net/20160822132834528?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
第二,在AndroidManfest.xml中加入:
顺便改变一下图标,用photoshop做图标,截四种规格的图标
![](https://img-blog.csdn.net/20160822132936858?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
android:icon="@mipmap/ic_launcher"
设置启动界面:
<activity
android:name=".ui.activity.WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
主要实现WelcomeActivity作为app进入的第一个界面,也就是启动界面。
第三,布局文件的书写:
<?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:background="@mipmap/bg_welcome" //用photoshop做的界面背景
tools:context=".ui.activity.WelcomeActivity">
<TextView
android:id="@+id/tv_taoyi_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="淘忆"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textSize="40sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/tv_taoyi_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_taoyi_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="喧闹城市,静谧之处"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textSize="18sp"
/>
</RelativeLayout>
用RelativeLayout和两个TextView就可以实现欢迎界面。
第四:WelcomeActivity.java的书写:
package
com.elainetaylor.blog.ui.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.elainetaylor.blog.R;
import com.elainetaylor.blog.common.BaseActivity;
import com.elainetaylor.blog.common.UrlUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class WelcomeActivity
extends BaseActivity { 自定义BaseActivity
private
TextView tvTaoyiNam,
tvTaoyiContent;
private boolean isFirstIn
= false;
private static final int TIME
= 3000;
private static final int GO_HOME
= 0;
private static final int GO_GUIDE
= 1;
private Handler
handler =
new Handler() { //接受信息来执行进入引导页还是主页
@Override
public void
handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case
GO_HOME:
new
Thread(new
Runnable() { //开启新线程避免出现卡顿现象
@Override
public void
run() {
tryLogin();
}
}).start();
goHome();
break;
case GO_GUIDE:
goGuide();
break;
}
}
};
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
init(); //初始化控件
initRequestQueue(); //初始化RequestQueue
write(); //写下isFirstIn的值
startAnimation(); //启动动画效果
}
public void
tryLogin() {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
final String username = sharedPreferences.getString("username",
"");
final String password = sharedPreferences.getString("password",
"");
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
{ //判断username和password是否为空
writeUserDataTwo();
}
else {
StringRequest request =
new StringRequest(Request.Method.POST,
UrlUtils.getLoginUrl(), new
Response.Listener<String>() {
@Override
public void
onResponse(String s) {
try
{ //json数据解析
JSONObject object =
new JSONObject(s);
String msg = object.getString("msg");
if (msg.equals("登陆成功")) { //这是根据服务器端传出的数据来判断的。
String userId = object.getString("userId");
writeUserData(userId);
}
else {
writeUserDataTwo();
}
} catch
(JSONException e) {
e.printStackTrace();
writeUserDataTwo();
}
}
}, new
Response.ErrorListener() {
@Override
public void
onErrorResponse(VolleyError volleyError) {
writeUserDataTwo();
}
}) {
//传入数据才可以提交判断是否登录成功
@Override
protected
Map<String,
String> getParams()
throws AuthFailureError {
Map<String,
String> params = new
HashMap<>();
params.put("username",
username);
params.put("password",
password);
return params;
}
};
addRequestQueue(request);
}
}
//如果登录成功则写下isLogin为true,并且写下userId
public void
writeUserData(String userId) {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLogin", true);
editor.putString("userId",
userId);
editor.apply();
}
//如果登录失败就写下isLogin为false
public void
writeUserDataTwo() {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLogin",false);
editor.apply();
}
public void
init() {
tvTaoyiNam
= (TextView) findViewById(R.id.tv_taoyi_name);
tvTaoyiContent
= (TextView) findViewById(R.id.tv_taoyi_content);
}
public void
write() {
SharedPreferences preferences = getSharedPreferences("isFirstIn",
MODE_PRIVATE);
isFirstIn
= preferences.getBoolean("isFirstIn", true);
if (!isFirstIn) {
handler.sendEmptyMessageDelayed(GO_HOME,
TIME);
}
else {
handler.sendEmptyMessageDelayed(GO_GUIDE,
TIME);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("isFirstIn", false);
editor.apply();
}
}
//用布局文件去调动动画效果
public void
startAnimation() {
Animation animation = AnimationUtils.loadAnimation(WelcomeActivity.this,
R.anim.welcome_text);
tvTaoyiNam.startAnimation(animation);
tvTaoyiContent.startAnimation(animation);
}
//主界面启动
public void
goHome() {
Intent i = new
Intent(WelcomeActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
//引导界面的启动
public void
goGuide() {
Intent intent = new
Intent(WelcomeActivity.this,
GuideActivity.class);
startActivity(intent);
finish();
}
}
第五:Welcome_text.xml的书写:
用布局文件会显得整体比较整洁,所以我用的是布局文件,比较方便。
<?xml version="1.0"
encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0">
第六:BaseActivity.java的书写:
private
RequestQueue queue;
public void initRequestQueue(){
queue= Volley.newRequestQueue(this);
}
public void addRequestQueue(StringRequest request){
queue.add(request);
}
加入RequestQueue的初始化和添加request的方法,这一步需要添加Volley的jar包。
第七:首先还是需要初始化一些界面的内容,建完项目之后,先初始化这些内容:
初始化style.xml中的颜色数据和ActionBar,title等。
<resources>
<!-- Base application theme. -->
<style
name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item
name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">#000</item>
<item name="colorAccent">#5cd0c2</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
color.xml文件中的三个数据:
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<color name="colorPrimary">#00b7ee</color>
<color name="colorPrimaryDark">#00b7ee</color>
<color name="colorAccent">#00b7ee</color>
</resources>
string.xml文件中的appName:
<resources>
<string name="app_name">淘忆</string>
</resources>
欢迎界面,简单明了的文字,突出app的主题加意义就可以了。
欢迎界面,第一个功能加入是否首次进入App的判定来表示欢迎界面之后是主界面还是引导界面,第二个功能是实现用户登录,这样加强用户的交互效果,让再次进入app的时候能够实现自动登录,避免用户多次登录的繁琐,第三个功能就是简单说明App的主旨。
第一:
用photoshop CC 2015.5绘制UI界面,并且用CutterMan截下图标背景等。
第二,在AndroidManfest.xml中加入:
顺便改变一下图标,用photoshop做图标,截四种规格的图标
android:icon="@mipmap/ic_launcher"
设置启动界面:
<activity
android:name=".ui.activity.WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
主要实现WelcomeActivity作为app进入的第一个界面,也就是启动界面。
第三,布局文件的书写:
<?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:background="@mipmap/bg_welcome" //用photoshop做的界面背景
tools:context=".ui.activity.WelcomeActivity">
<TextView
android:id="@+id/tv_taoyi_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="淘忆"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textSize="40sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/tv_taoyi_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_taoyi_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="喧闹城市,静谧之处"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textSize="18sp"
/>
</RelativeLayout>
用RelativeLayout和两个TextView就可以实现欢迎界面。
第四:WelcomeActivity.java的书写:
package
com.elainetaylor.blog.ui.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.elainetaylor.blog.R;
import com.elainetaylor.blog.common.BaseActivity;
import com.elainetaylor.blog.common.UrlUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class WelcomeActivity
extends BaseActivity { 自定义BaseActivity
private
TextView tvTaoyiNam,
tvTaoyiContent;
private boolean isFirstIn
= false;
private static final int TIME
= 3000;
private static final int GO_HOME
= 0;
private static final int GO_GUIDE
= 1;
private Handler
handler =
new Handler() { //接受信息来执行进入引导页还是主页
@Override
public void
handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case
GO_HOME:
new
Thread(new
Runnable() { //开启新线程避免出现卡顿现象
@Override
public void
run() {
tryLogin();
}
}).start();
goHome();
break;
case GO_GUIDE:
goGuide();
break;
}
}
};
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
init(); //初始化控件
initRequestQueue(); //初始化RequestQueue
write(); //写下isFirstIn的值
startAnimation(); //启动动画效果
}
public void
tryLogin() {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
final String username = sharedPreferences.getString("username",
"");
final String password = sharedPreferences.getString("password",
"");
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
{ //判断username和password是否为空
writeUserDataTwo();
}
else {
StringRequest request =
new StringRequest(Request.Method.POST,
UrlUtils.getLoginUrl(), new
Response.Listener<String>() {
@Override
public void
onResponse(String s) {
try
{ //json数据解析
JSONObject object =
new JSONObject(s);
String msg = object.getString("msg");
if (msg.equals("登陆成功")) { //这是根据服务器端传出的数据来判断的。
String userId = object.getString("userId");
writeUserData(userId);
}
else {
writeUserDataTwo();
}
} catch
(JSONException e) {
e.printStackTrace();
writeUserDataTwo();
}
}
}, new
Response.ErrorListener() {
@Override
public void
onErrorResponse(VolleyError volleyError) {
writeUserDataTwo();
}
}) {
//传入数据才可以提交判断是否登录成功
@Override
protected
Map<String,
String> getParams()
throws AuthFailureError {
Map<String,
String> params = new
HashMap<>();
params.put("username",
username);
params.put("password",
password);
return params;
}
};
addRequestQueue(request);
}
}
//如果登录成功则写下isLogin为true,并且写下userId
public void
writeUserData(String userId) {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLogin", true);
editor.putString("userId",
userId);
editor.apply();
}
//如果登录失败就写下isLogin为false
public void
writeUserDataTwo() {
SharedPreferences sharedPreferences = getSharedPreferences("mes",
MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLogin",false);
editor.apply();
}
public void
init() {
tvTaoyiNam
= (TextView) findViewById(R.id.tv_taoyi_name);
tvTaoyiContent
= (TextView) findViewById(R.id.tv_taoyi_content);
}
public void
write() {
SharedPreferences preferences = getSharedPreferences("isFirstIn",
MODE_PRIVATE);
isFirstIn
= preferences.getBoolean("isFirstIn", true);
if (!isFirstIn) {
handler.sendEmptyMessageDelayed(GO_HOME,
TIME);
}
else {
handler.sendEmptyMessageDelayed(GO_GUIDE,
TIME);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("isFirstIn", false);
editor.apply();
}
}
//用布局文件去调动动画效果
public void
startAnimation() {
Animation animation = AnimationUtils.loadAnimation(WelcomeActivity.this,
R.anim.welcome_text);
tvTaoyiNam.startAnimation(animation);
tvTaoyiContent.startAnimation(animation);
}
//主界面启动
public void
goHome() {
Intent i = new
Intent(WelcomeActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
//引导界面的启动
public void
goGuide() {
Intent intent = new
Intent(WelcomeActivity.this,
GuideActivity.class);
startActivity(intent);
finish();
}
}
第五:Welcome_text.xml的书写:
用布局文件会显得整体比较整洁,所以我用的是布局文件,比较方便。
<?xml version="1.0"
encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0">
第六:BaseActivity.java的书写:
private
RequestQueue queue;
public void initRequestQueue(){
queue= Volley.newRequestQueue(this);
}
public void addRequestQueue(StringRequest request){
queue.add(request);
}
加入RequestQueue的初始化和添加request的方法,这一步需要添加Volley的jar包。
第七:首先还是需要初始化一些界面的内容,建完项目之后,先初始化这些内容:
初始化style.xml中的颜色数据和ActionBar,title等。
<resources>
<!-- Base application theme. -->
<style
name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item
name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">#000</item>
<item name="colorAccent">#5cd0c2</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
color.xml文件中的三个数据:
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<color name="colorPrimary">#00b7ee</color>
<color name="colorPrimaryDark">#00b7ee</color>
<color name="colorAccent">#00b7ee</color>
</resources>
string.xml文件中的appName:
<resources>
<string name="app_name">淘忆</string>
</resources>
相关文章推荐
- 淘忆项目之分享界面服务器端的修正归纳
- 淘忆项目之分享界面客户端的修正归纳
- 淘忆项目之引导界面的分享归纳
- 淘忆项目之主页界面服务器端的修正归纳
- 淘忆项目之登录界面的修正归纳
- 淘忆项目之主页界面客户端的整理归纳
- 淘忆项目之主题界面的修正归纳
- 淘忆项目之主题详情界面的修正归纳
- 淘忆项目之注册界面的修正归纳
- 淘忆项目之忘记密码界面的修正归纳
- 从零开发一个完整的Android项目(六)——欢迎(登陆)界面
- 项目开发通用欢迎界面
- Android项目实战(一):口袋中国Android安卓手机客户端1.0版之欢迎界面
- 安卓项目欢迎界面效果制作(界面显示应用版本信息)
- 修改Tomcat欢迎界面为自己项目界面 localhost进入你部署的项
- Tomcat 可以正常启动你的项目 但是直接用端口进入不了tomcat的欢迎界面
- Android基础知识【项目实训-欢迎界面和生成数据库】【2】
- 【无私分享:从入门到精通ASP.NET MVC】从0开始,一起搭框架、做项目 登录界面前端样式和特效
- 一个比较酷的项目界面分享,干货十足
- Android项目中的欢迎界面和引导页:动画和ViewPager