Android仿新浪微博啟動界面或登陸界面(1)
本文為大家分享了Android模仿新浪微博啟動界面&登陸界面的具體實現(xiàn)代碼,供大家參考,具體內(nèi)容如下
啟動界面
主要有兩個功能:
1.加載啟動動畫
2.判斷網(wǎng)絡,有者直接進入登陸界面,否則去設置網(wǎng)絡
代碼較簡單,主要采用AlphaAnimation()方法和動畫監(jiān)聽器,使一張圖片產(chǎn)生漸變動畫。在動畫啟動的時候判斷網(wǎng)絡,動畫結(jié)束時完成判斷并進入登陸界面。
/** * 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); //將組件和動畫進行關聯(lián) splashimage.setAnimation(animation); animation.setAnimationListener(new Animation.AnimationListener() { //動畫啟動執(zhí)行 @Override public void onAnimationStart(Animation animation) { Toast.makeText(SplashActivity.this, "歡迎使用DeMon制作微博", Toast.LENGTH_LONG).show(); //檢查并網(wǎng)絡的方法 Tools.checkNetWork(SplashActivity.this); } //動畫結(jié)束執(zhí)行 @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); } //動畫重復執(zhí)行 @Override public void onAnimationRepeat(Animation animation) { } }); }
使用ConnectivityManager獲取系統(tǒng)的連接服務,然后獲取代表聯(lián)網(wǎng)狀態(tài)的NetWorkInfo對象,獲取網(wǎng)絡的連接情況,如果沒有網(wǎng)絡則生成一個AlertDialog引導進行網(wǎng)絡設置。該方法位于Tools.java中。
/** * 設置網(wǎng)絡 * * @param context */ public static void checkNetWork(final SplashActivity context) { if (!NetWorkStatus(context)) { TextView msg = new TextView(context); msg.setText("請設置網(wǎng)絡!"); AlertDialog.Builder b = new AlertDialog.Builder(context). setIcon(R.drawable.notnet) .setTitle("沒有可用的網(wǎng)絡") .setMessage("是否對網(wǎng)絡進行設置?"); b.setPositiveButton("是", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //跳轉(zhuǎn)到設置網(wǎng)絡界面 context.startActivity(new Intent(Settings.ACTION_SETTINGS)); } }).setNeutralButton("否", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); context.finish(); } }).create().show(); } } /** * 判斷網(wǎng)絡狀態(tài) */ public static boolean NetWorkStatus(Context context) { //獲取系統(tǒng)的連接服務 ConnectivityManager connect = (ConnectivityManager) context.getSystemService(Context .CONNECTIVITY_SERVICE); if (connect == null) { return false; } else { // 獲取代表聯(lián)網(wǎng)狀態(tài)的NetWorkInfo對象,獲取網(wǎng)絡的連接情況 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>
登陸界面
此界面只有幾個按鈕,故合在一條博客里。
微博按鈕觸發(fā)進入到到授權(quán)界面
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>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android筆記之:App應用之啟動界面SplashActivity的使用
- 詳解Android中App的啟動界面Splash的編寫方法
- Android開發(fā)基礎之創(chuàng)建啟動界面Splash Screen的方法
- Android 個人理財工具一:項目概述與啟動界面的實現(xiàn)
- Android編程實現(xiàn)啟動界面的方法分析
- Android 應用啟動歡迎界面廣告的實現(xiàn)實例
- Android UI設計與開發(fā)之實現(xiàn)應用程序只啟動一次引導界面
- Android 避免APP啟動閃黑屏的解決辦法(Theme和Style)
- Android啟動畫面的實現(xiàn)方法
- Android開發(fā)中簡單設置啟動界面的方法
相關文章
SQLSERVER實現(xiàn)更改表名,更改列名,更改約束代碼
這篇文章主要介紹了SQLSERVER實現(xiàn)更改表名,更改列名,更改約束代碼的相關資料,需要的朋友可以參考下2016-03-03Android開發(fā)中ViewPager實現(xiàn)多頁面切換效果
ViewPager用于實現(xiàn)多頁面的切換效果,該類存在于Google的兼容包里面,所以在引用時記得在BuilldPath中加入“Android-support-v4.jar”。具體詳情大家可以參考下本文2016-11-11webview添加參數(shù)與修改請求頭的user-agent實例
這篇文章主要介紹了webview添加參數(shù)與修改請求頭的user-agent實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03