Android仿新浪微博啟動介面或登陸介面(1)_Android

來源:互聯網
上載者:User

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

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.