android開發(fā)之歡迎界面的小例子
首先你得寫好xml文件,這也是最主要的。
然后,在activity中加入一個(gè)線程,延時(shí)2秒,用來跳轉(zhuǎn)到主界面。
activity中線程代碼如下:(順便檢測一下網(wǎng)絡(luò)是否打開)
[java]
@Override
protected void onStart() {
super.onStart();
if(<SPAN style="COLOR: #ff0000">isNetworkConnected()</SPAN>){
new Thread(){
@Override
public void run() {
try {
Thread.sleep(2000);
Intent intent = new Intent(<SPAN style="COLOR: #ff0000">SplashActivity.this</SPAN>,<SPAN style="COLOR: #ff0000">CompusAssistMain.class</SPAN>);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}else{
//彈出對話框 讓用戶設(shè)置網(wǎng)絡(luò)
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("設(shè)置網(wǎng)絡(luò)");
builder.setMessage("網(wǎng)絡(luò)錯(cuò)誤請?jiān)O(shè)置網(wǎng)絡(luò)");
builder.setPositiveButton("設(shè)置網(wǎng)絡(luò)", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setClassName(<SPAN style="COLOR: #ff6666">"com.android.settings"</SPAN>, <SPAN style="COLOR: #ff6666">"com.android.settings.WirelessSettings"</SPAN>);
startActivity(intent);
}
});
builder.setNegativeButton("取消", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.create().show();
}
}
@Override
protected void onStart() {
super.onStart();
if(isNetworkConnected()){
new Thread(){
@Override
public void run() {
try {
Thread.sleep(2000);
Intent intent = new Intent(SplashActivity.this,CompusAssistMain.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}else{
//彈出對話框 讓用戶設(shè)置網(wǎng)絡(luò)
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("設(shè)置網(wǎng)絡(luò)");
builder.setMessage("網(wǎng)絡(luò)錯(cuò)誤請?jiān)O(shè)置網(wǎng)絡(luò)");
builder.setPositiveButton("設(shè)置網(wǎng)絡(luò)", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
startActivity(intent);
}
});
builder.setNegativeButton("取消", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.create().show();
}
}檢測網(wǎng)絡(luò)的類isNetWorkConnected():
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 判斷系統(tǒng)的網(wǎng)絡(luò)是否可用
* @return
*/
private boolean isNetworkConnected(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo info =cm.getActiveNetworkInfo();
if(info!=null&&info.isConnected()){
return true;
}else {
return false ;
}
/**
* 判斷系統(tǒng)的網(wǎng)絡(luò)是否可用
* @return
*/
private boolean isNetworkConnected(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo info =cm.getActiveNetworkInfo();
if(info!=null&&info.isConnected()){
return true;
}else {
return false ;
}
這樣就完成了一個(gè)歡迎界面,給自已的應(yīng)用加點(diǎn)色彩。當(dāng)然還要添加配置在Manifest文件中
[html]
<activity
android:name="com.yan.compusassist.SplashActivity"
android:label="@string/application_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.yan.compusassist.SplashActivity"
android:label="@string/application_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
這樣它就會(huì)打開應(yīng)用,啟動(dòng)第一個(gè)activity 界面。
- android實(shí)現(xiàn)歡迎界面效果
- Android ListView仿微信聊天界面
- Android登錄界面的實(shí)現(xiàn)代碼分享
- Android設(shè)計(jì)登錄界面、找回密碼、注冊功能
- Android實(shí)現(xiàn)簡潔的APP登錄界面
- 功能強(qiáng)大的登錄界面Android實(shí)現(xiàn)代碼
- Android用戶注冊界面簡單設(shè)計(jì)
- Android開發(fā)實(shí)例之登錄界面的實(shí)現(xiàn)
- android 引導(dǎo)界面的實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)友好崩潰界面
相關(guān)文章
Android Studio報(bào)錯(cuò)unable to access android sdk add-on list解決方案
這篇文章主要介紹了Android Studio報(bào)錯(cuò)unable to access android sdk add-on list解決方案,本文通過多種方式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03Android實(shí)現(xiàn)關(guān)機(jī)后數(shù)據(jù)不會(huì)丟失問題
這篇文章主要介紹了Android實(shí)現(xiàn)關(guān)機(jī)后數(shù)據(jù)不會(huì)丟失問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10Android 動(dòng)畫之TranslateAnimation應(yīng)用詳解
本節(jié)講解TranslateAnimation動(dòng)畫,TranslateAnimation比較常用,比如QQ,網(wǎng)易新聞菜單條的動(dòng)畫,就可以用TranslateAnimation實(shí)現(xiàn),本文將詳細(xì)介紹通過TranslateAnimation 來定義動(dòng)畫,需要的朋友可以參考下2012-12-12解析Android 8.1平臺(tái)SystemUI 導(dǎo)航欄加載流程
這篇文章主要介紹了Android 8.1平臺(tái)SystemUI 導(dǎo)航欄加載流程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11Android開發(fā)中遇到端口號(hào)占用問題解決方法
這篇文章主要介紹了Android開發(fā)中遇到端口號(hào)占用問題解決方法,本文給出了一個(gè)簡潔實(shí)用的方法來解決這個(gè)煩人的問題,需要的朋友可以參考下2015-06-06Android開發(fā)自定義短信驗(yàn)證碼實(shí)現(xiàn)過程詳解
這篇文章主要為大家介紹了Android開發(fā)自定義短信驗(yàn)證碼實(shí)現(xiàn)過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06Android補(bǔ)間動(dòng)畫的實(shí)現(xiàn)示例
本文主要介紹了Android補(bǔ)間動(dòng)畫的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽
如果您要顯示敏感數(shù)據(jù),例如錢包金額,或者只是當(dāng)?shù)卿洷韱物@示插入的密碼清晰時(shí),當(dāng)您不在應(yīng)用程序中時(shí),您必須隱藏敏感數(shù)據(jù)。本文將利用Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽,需要的可以參考一下2022-06-06