Android仿新浪微博啟動(dòng)界面或登陸界面(1)
本文為大家分享了Android模仿新浪微博啟動(dòng)界面&登陸界面的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
啟動(dòng)界面
主要有兩個(gè)功能:
1.加載啟動(dòng)動(dòng)畫(huà)
2.判斷網(wǎng)絡(luò),有者直接進(jìn)入登陸界面,否則去設(shè)置網(wǎng)絡(luò)
代碼較簡(jiǎn)單,主要采用AlphaAnimation()方法和動(dòng)畫(huà)監(jiān)聽(tīng)器,使一張圖片產(chǎn)生漸變動(dòng)畫(huà)。在動(dòng)畫(huà)啟動(dòng)的時(shí)候判斷網(wǎng)絡(luò),動(dòng)畫(huà)結(jié)束時(shí)完成判斷并進(jìn)入登陸界面。
/**
* Created by D&LL on 2016/5/25.
* 初始頁(yè)面加載界面
*/
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);
//透明度漸變動(dòng)畫(huà)
AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f);
//設(shè)置動(dòng)畫(huà)時(shí)長(zhǎng)
animation.setDuration(3000);
//將組件和動(dòng)畫(huà)進(jìn)行關(guān)聯(lián)
splashimage.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
//動(dòng)畫(huà)啟動(dòng)執(zhí)行
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(SplashActivity.this, "歡迎使用DeMon制作微博", Toast.LENGTH_LONG).show();
//檢查并網(wǎng)絡(luò)的方法
Tools.checkNetWork(SplashActivity.this);
}
//動(dòng)畫(huà)結(jié)束執(zhí)行
@Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
//動(dòng)畫(huà)重復(fù)執(zhí)行
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
使用ConnectivityManager獲取系統(tǒng)的連接服務(wù),然后獲取代表聯(lián)網(wǎng)狀態(tài)的NetWorkInfo對(duì)象,獲取網(wǎng)絡(luò)的連接情況,如果沒(méi)有網(wǎng)絡(luò)則生成一個(gè)AlertDialog引導(dǎo)進(jìn)行網(wǎng)絡(luò)設(shè)置。該方法位于Tools.java中。
/**
* 設(shè)置網(wǎng)絡(luò)
*
* @param context
*/
public static void checkNetWork(final SplashActivity context) {
if (!NetWorkStatus(context)) {
TextView msg = new TextView(context);
msg.setText("請(qǐng)?jiān)O(shè)置網(wǎng)絡(luò)!");
AlertDialog.Builder b = new AlertDialog.Builder(context).
setIcon(R.drawable.notnet)
.setTitle("沒(méi)有可用的網(wǎng)絡(luò)")
.setMessage("是否對(duì)網(wǎng)絡(luò)進(jìn)行設(shè)置?");
b.setPositiveButton("是", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//跳轉(zhuǎn)到設(shè)置網(wǎng)絡(luò)界面
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)絡(luò)狀態(tài)
*/
public static boolean NetWorkStatus(Context context) {
//獲取系統(tǒng)的連接服務(wù)
ConnectivityManager connect = (ConnectivityManager) context.getSystemService(Context
.CONNECTIVITY_SERVICE);
if (connect == null) {
return false;
} else {
// 獲取代表聯(lián)網(wǎng)狀態(tài)的NetWorkInfo對(duì)象,獲取網(wǎng)絡(luò)的連接情況
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>

登陸界面
此界面只有幾個(gè)按鈕,故合在一條博客里。
微博按鈕觸發(fā)進(jìn)入到到授權(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兩個(gè)自定義樣式的EditText,一個(gè)普通按鈕(此處純粹擺設(shè))。只有微博登陸按鈕有用。
<?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>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android筆記之:App應(yīng)用之啟動(dòng)界面SplashActivity的使用
- 詳解Android中App的啟動(dòng)界面Splash的編寫(xiě)方法
- Android開(kāi)發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法
- Android 個(gè)人理財(cái)工具一:項(xiàng)目概述與啟動(dòng)界面的實(shí)現(xiàn)
- Android編程實(shí)現(xiàn)啟動(dòng)界面的方法分析
- Android 應(yīng)用啟動(dòng)歡迎界面廣告的實(shí)現(xiàn)實(shí)例
- Android UI設(shè)計(jì)與開(kāi)發(fā)之實(shí)現(xiàn)應(yīng)用程序只啟動(dòng)一次引導(dǎo)界面
- Android 避免APP啟動(dòng)閃黑屏的解決辦法(Theme和Style)
- Android啟動(dòng)畫(huà)面的實(shí)現(xiàn)方法
- Android開(kāi)發(fā)中簡(jiǎn)單設(shè)置啟動(dòng)界面的方法
相關(guān)文章
Android 開(kāi)源項(xiàng)目側(cè)邊欄菜單(SlidingMenu)使用詳解
SlidingMenu的是一種比較新的設(shè)置界面或配置界面效果,在主界面左滑或者右滑出現(xiàn)設(shè)置界面,能方便的進(jìn)行各種操作.目前有大量的應(yīng)用都在使用這一效果。如Evernote、Google+、Foursquare等,國(guó)內(nèi)的豌豆夾,人人,360手機(jī)助手等都使用SlidingMenu的界面方案。2016-05-05
Android 判斷日期是否在一年以內(nèi)的算法實(shí)例
下面小編就為大家?guī)?lái)一篇Android 判斷日期是否在一年以內(nèi)的算法實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
Android應(yīng)用中使用ViewPager實(shí)現(xiàn)類(lèi)似QQ的界面切換效果
這篇文章主要介紹了Android應(yīng)用中使用ViewPager實(shí)現(xiàn)類(lèi)似QQ的界面切換效果的示例,文中的例子重寫(xiě)了PagerAdapter,并且講解了如何解決Android下ViewPager和PagerAdapter中調(diào)用notifyDataSetChanged失效的問(wèn)題,需要的朋友可以參考下2016-03-03
詳解 Kotlin Reference Basic Types, String, Array and Imports
這篇文章主要介紹了詳解 Kotlin Reference Basic Types, String, Array and Imports的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android側(cè)滑菜單控件DrawerLayout使用詳解
這篇文章主要為大家詳細(xì)介紹了Android側(cè)滑菜單控件DrawerLayout的使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
設(shè)置Android設(shè)備WIFI在休眠時(shí)永不斷開(kāi)的代碼實(shí)現(xiàn)
這篇文章主要介紹了設(shè)置Android設(shè)備WIFI在休眠時(shí)永不斷開(kāi)的代碼實(shí)現(xiàn),需要的朋友可以參考下2014-07-07
Android 實(shí)現(xiàn)圓角圖片的簡(jiǎn)單實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)圓角圖片的簡(jiǎn)單實(shí)例的相關(guān)資料,Android 圓角圖片的實(shí)現(xiàn)形式,包括用第三方、也有系統(tǒng),需要的朋友可以參考下2017-07-07

