当前位置: 移动技术网 > IT编程>移动开发>Android > Android仿新浪微博启动界面或登陆界面(1)

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

生源地助学贷款网址,德宏师专,无线网络密码破解器

本文为大家分享了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>

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网