Android仿新浪微博启动界面或登陆界面(1)

本文为大家分享了Android模仿新浪微博启动界面&登陆界面的具体实现代码,供大家参考,具体内容如下

启动界面

主要有两个功能:

1.加载启动动画
2.判断网络,有者直接进入登陆界面,否则去设置网络

代码较简单,主要采用AlphaAnimation()方法和动画监听器,使一张图片产生渐变动画。在动画启动的时候判断网络,动画结束时完成判断并进入登陆界面。

/** * Created by D&LL on 2016/5/25. * 初始页面加载界面 */ public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); ImageView splashimage = (ImageView) findViewById(R.id.splashimage); //透明度渐变动画 AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f); //设置动画时长 animation.setDuration(3000); //将组件和动画进行关联 splashimage.setAnimation(animation); animation.setAnimationListener(new Animation.AnimationListener() { //动画启动执行 @Override public void onAnimationStart(Animation animation) { Toast.makeText(SplashActivity.this, "欢迎使用DeMon制作微博", Toast.LENGTH_LONG).show(); //检查并网络的方法 Tools.checkNetWork(SplashActivity.this); } //动画结束执行 @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); } //动画重复执行 @Override public void onAnimationRepeat(Animation animation) { } }); }

使用ConnectivityManager获取系统的连接服务,然后获取代表联网状态的NetWorkInfo对象,获取网络的连接情况,如果没有网络则生成一个AlertDialog引导进行网络设置。该方法位于Tools.java中。

/** * 设置网络 * * @param context */ public static void checkNetWork(final SplashActivity context) { if (!NetWorkStatus(context)) { TextView msg = new TextView(context); msg.setText("请设置网络!"); AlertDialog.Builder b = new AlertDialog.Builder(context). setIcon(R.drawable.notnet) .setTitle("没有可用的网络") .setMessage("是否对网络进行设置?"); b.setPositiveButton("是", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //跳转到设置网络界面 context.startActivity(new Intent(Settings.ACTION_SETTINGS)); } }).setNeutralButton("否", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); context.finish(); } }).create().show(); } } /** * 判断网络状态 */ public static boolean NetWorkStatus(Context context) { //获取系统的连接服务 ConnectivityManager connect = (ConnectivityManager) context.getSystemService(Context .CONNECTIVITY_SERVICE); if (connect == null) { return false; } else { // 获取代表联网状态的NetWorkInfo对象,获取网络的连接情况 NetworkInfo[] infos = connect.getAllNetworkInfo(); if (infos != null) { for (NetworkInfo network : infos) { if (network.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }

SplashActivity的布局文件splash.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/splashimage" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/splashimage"/> <ProgressBar style="@android:style/Widget.ProgressBar.Inverse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentStart="true" android:layout_gravity="center" android:layout_marginBottom="64dp" android:layout_marginStart="130dp"> </ProgressBar> </RelativeLayout>

登陆界面

此界面只有几个按钮,故合在一条博客里。

微博按钮触发进入到到授权界面

public class LoginActivity extends Activity { private Button sinalogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); sinalogin = (Button) findViewById(R.id.sinalogin); sinalogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(LoginActivity.this, OAuthActivity.class); startActivity(intent); LoginActivity.this.finish(); } }); } }

布局文件login.xml两个自定义样式的EditText,一个普通按钮(此处纯粹摆设)。只有微博登陆按钮有用。

<?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:background="@drawable/background" android:gravity="center_vertical" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="40dip" android:background="@drawable/bg_edittext" android:ems="10" android:inputType="textPersonName"> </EditText> <EditText android:id="@+id/passworld" android:layout_width="match_parent" android:layout_height="40dip" android:layout_marginTop="20dip" android:background="@drawable/bg_edittext" android:ems="10" android:inputType="textPassword"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/login" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginTop="20dip" android:layout_weight="1" android:text="登录"/> <Button android:id="@+id/sinalogin" android:layout_width="200dp" android:layout_height="38dp" android:layout_marginTop="20dip" android:layout_weight="1" android:background="@drawable/weibologin"/> </LinearLayout> </LinearLayout>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

时间: 2024-09-08 06:09:38

Android仿新浪微博启动界面或登陆界面(1)的相关文章

Android仿新浪微博启动界面或登陆界面(1)_Android

本文为大家分享了Android模仿新浪微博启动界面&登陆界面的具体实现代码,供大家参考,具体内容如下 启动界面 主要有两个功能: 1.加载启动动画 2.判断网络,有者直接进入登陆界面,否则去设置网络 代码较简单,主要采用AlphaAnimation()方法和动画监听器,使一张图片产生渐变动画.在动画启动的时候判断网络,动画结束时完成判断并进入登陆界面. /** * Created by D&LL on 2016/5/25. * 初始页面加载界面 */ public class Splash

Android仿新浪微博分页管理界面(3)

本文实例为大家分享了Android仿新浪微博分页管理界面的具体代码,供大家参考,具体内容如下 多个activity分页管理,为了方便获取上下文,采用继承TabActivity的传统方法. 大致思路:使用RadioGroup点击触发不同的选卡项,选卡项绑定不同的activiity,进而进行分页管理.详解见注解. /** * 主Activity * 通过点击RadioGroup下的RadioButton来切换不同界面 * Created by D&LL on 2016/7/20. */ public

Android仿新浪微博oauth2.0授权界面实现代码(2)_Android

oauth2.0授权界面,大致流程图: 前提准备: 在新浪开放平台申请appkey和appsecret:http://open.weibo.com/. 熟悉oauth2.0协议,相关知识:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html OAuth2的access_token接口:http://open.weibo.com/wiki/OAuth2/access_token 代码详解 大致思路如下:建立一个webview加载授权界面,授权回

Android仿新浪微博发布微博界面设计(5)_Android

本教程为大家分享了Android发布微博.添加表情等功能的具体代码,供大家参考,具体内容如下 发布一条新微博接口:http://open.weibo.com/wiki/2/statuses/update 上传图片并发布一条新微博接口:http://open.weibo.com/wiki/2/statuses/upload 1.根据有没有图片来选择相应的接口. 2.根据输入框的改变判断文字数. 3.创建一个girlview显示发送的图片,最最多9张,此处由于请求参数的的原因,最多上传一张图片,选择

Android仿新浪微博oauth2.0授权界面实现代码(2)

oauth2.0授权界面,大致流程图: 前提准备: 在新浪开放平台申请appkey和appsecret:http://open.weibo.com/. 熟悉oauth2.0协议,相关知识:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html OAuth2的access_token接口:http://open.weibo.com/wiki/OAuth2/access_token 代码详解 大致思路如下:建立一个webview加载授权界面,授权回

Android仿新浪微博个人信息界面及其他效果

本教程为大家分享了Android微博个人信息界面设计代码,供大家参考,具体内容如下 根据用户ID获取用户信息接口: http://open.weibo.com/wiki/2/users/show 如果你已经实现前面的功能那个这个人信息界面便是小菜一碟,此处不作叙述. 补充 1.时间处理类: 处理微博发出时间距现在时刻的时间.应该是比较容易理解的. /** * 时间处理类 */ public class DateUtils { public String getInterval(String cr

Android仿新浪微博发布微博界面设计(5)

本教程为大家分享了Android发布微博.添加表情等功能的具体代码,供大家参考,具体内容如下 发布一条新微博接口:http://open.weibo.com/wiki/2/statuses/update 上传图片并发布一条新微博接口:http://open.weibo.com/wiki/2/statuses/upload 1.根据有没有图片来选择相应的接口. 2.根据输入框的改变判断文字数. 3.创建一个girlview显示发送的图片,最最多9张,此处由于请求参数的的原因,最多上传一张图片,选择

Android仿Win8的metro的UI界面(上)_Android

手机下载了一些APP,发现现在仿win8的主界面越来越多,在大家见惯了类GridView或者类Tab后,给人一种耳目一新的感觉.今天在eoe上偶然发现已经有人实现了这个功能的源码(地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=327557),马上下载跑了一下,效果很炫,但是有些bug,比如点击速度特别快时图像会被放大,以及点击时会触发两次点击事件. 本例子基于eoe中这位大神的实现,做了一些简化,和bug的修复. 效果: 首先

Android仿Win8的metro的UI界面(上)

手机下载了一些APP,发现现在仿win8的主界面越来越多,在大家见惯了类GridView或者类Tab后,给人一种耳目一新的感觉.今天在eoe上偶然发现已经有人实现了这个功能的源码(地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=327557),马上下载跑了一下,效果很炫,但是有些bug,比如点击速度特别快时图像会被放大,以及点击时会触发两次点击事件. 本例子基于eoe中这位大神的实现,做了一些简化,和bug的修复. 效果: 首先