Android開(kāi)發(fā)歡迎頁(yè)點(diǎn)擊跳過(guò)倒計(jì)時(shí)進(jìn)入主頁(yè)
沒(méi)點(diǎn)擊跳過(guò)自然進(jìn)入主頁(yè),點(diǎn)擊跳過(guò)之后立即進(jìn)入主頁(yè)


1.歡迎頁(yè)布局activity_sp.xml放一張背景圖(圖片隨你便啦)再放一個(gè)盛放倒計(jì)時(shí)的TextView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/a">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>2.主要java代碼
package com.cwj.test;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
public class SpActivity extends AppCompatActivity implements View.OnClickListener {
private int recLen = 5;//跳過(guò)倒計(jì)時(shí)提示5秒
private TextView tv;
Timer timer = new Timer();
private Handler handler;
private Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//定義全屏參數(shù)
int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//設(shè)置當(dāng)前窗體為全屏顯示
getWindow().setFlags(flag, flag);
setContentView(R.layout.activity_sp);
initView();
timer.schedule(task, 1000, 1000);//等待時(shí)間一秒,停頓時(shí)間一秒
/**
* 正常情況下不點(diǎn)擊跳過(guò)
*/
handler = new Handler();
handler.postDelayed(runnable = new Runnable() {
@Override
public void run() {
//從閃屏界面跳轉(zhuǎn)到首界面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 5000);//延遲5S后發(fā)送handler信息
}
private void initView() {
tv = findViewById(R.id.tv);//跳過(guò)
tv.setOnClickListener(this);//跳過(guò)監(jiān)聽(tīng)
}
TimerTask task = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() { // UI thread
@Override
public void run() {
recLen--;
tv.setText("跳過(guò) " + recLen);
if (recLen < 0) {
timer.cancel();
tv.setVisibility(View.GONE);//倒計(jì)時(shí)到0隱藏字體
}
}
});
}
};
/**
* 點(diǎn)擊跳過(guò)
*/
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv:
//從閃屏界面跳轉(zhuǎn)到首界面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
if (runnable != null) {
handler.removeCallbacks(runnable);
}
break;
default:
break;
}
}
}這里style里改了樣式,沒(méi)有標(biāo)題欄Theme.AppCompat.Light.NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>補(bǔ)充:
Android程序跳過(guò)登錄界面直接進(jìn)入主界面(自動(dòng)登錄)
首先是歡迎界面的代碼
public class WelcomeActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
/**
* 延遲3秒進(jìn)入主界面
*/
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
WelcomeActivity.this.finish();
}
},1000*3);
}
}接下來(lái)是文章的主要內(nèi)容。實(shí)現(xiàn)自動(dòng)登錄的關(guān)鍵是當(dāng)程序從歡迎界面跳轉(zhuǎn)到登錄界面是,在登錄界面還沒(méi)有加載布局文件時(shí)判斷是否登陸過(guò),從而實(shí)現(xiàn)直接跳轉(zhuǎn)到主界面。這里我們采用SharedPreferences來(lái)保存登錄狀態(tài)。代碼如下:
public class LoginActivity extends Activity{
SharedPreferences sprfMain;
SharedPreferences.Editor editorMain;
Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//在加載布局文件前判斷是否登陸過(guò)
sprfMain= PreferenceManager.getDefaultSharedPreferences(this);
editorMain=sprfMain.edit();
//.getBoolean("main",false);當(dāng)找不到"main"所對(duì)應(yīng)的鍵值是默認(rèn)返回false
if(sprfMain.getBoolean("main",false)){
Intent intent=new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
LoginActivity.this.finish();
}
setContentView(R.layout.login);
login= (Button) findViewById(R.id.login);
//這里只是簡(jiǎn)單用按鍵模擬登錄功能
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(LoginActivity.this,MainActivity.class);
editorMain.putBoolean("main",true);
editorMain.commit();
startActivity(intent);
LoginActivity.this.finish();
}
});
}
}接下來(lái)是實(shí)現(xiàn)注銷后要重新進(jìn)入登錄界面
public class MainActivity extends AppCompatActivity {
SharedPreferences sprfMain;
SharedPreferences.Editor editorMain;
Button exit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
exit= (Button) findViewById(R.id.exit);
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//點(diǎn)擊注銷按鍵后調(diào)用LoginActivity提供的resetSprfMain()方法執(zhí)行editorMain.putBoolean("main",false);,即將"main"對(duì)應(yīng)的值修改為false
resetSprfMain();
Intent intent=new Intent(MainActivity.this,WelcomeActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
});
}
public void resetSprfMain(){
sprfMain= PreferenceManager.getDefaultSharedPreferences(this);
editorMain=sprfMain.edit();
editorMain.putBoolean("main",false);
editorMain.commit();
}
}到此這篇關(guān)于Android開(kāi)發(fā)歡迎頁(yè)點(diǎn)擊跳過(guò)倒計(jì)時(shí)進(jìn)入主頁(yè)的文章就介紹到這了,更多相關(guān)Android點(diǎn)擊跳過(guò)倒計(jì)時(shí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android利用CountDownTimer實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- Android實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- Android賬號(hào)注冊(cè)實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- Android中TextView實(shí)現(xiàn)部分文字可點(diǎn)擊跳轉(zhuǎn)
- Android studio點(diǎn)擊跳轉(zhuǎn)WebView詳解
- Android中TextView自動(dòng)識(shí)別url且實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)
- Android TextView中文本點(diǎn)擊文字跳轉(zhuǎn) (代碼簡(jiǎn)單)
相關(guān)文章
解決AndroidStudio無(wú)法運(yùn)行java中的mian方法問(wèn)題
這篇文章主要介紹了解決AndroidStudio無(wú)法運(yùn)行java中的mian方法問(wèn)題,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
android中ListView多次刷新重復(fù)執(zhí)行g(shù)etView的解決方法
以前倒是沒(méi)有注意listview的getView會(huì)重復(fù)執(zhí)行多次,在測(cè)試的時(shí)候去斷點(diǎn)跟蹤,發(fā)現(xiàn)同一條數(shù)據(jù)不斷的重復(fù)執(zhí)行,下面與大家分享下正確的解決方法,希望對(duì)你有所幫助2013-06-06
Android利用屬性動(dòng)畫(huà)實(shí)現(xiàn)優(yōu)酷菜單
這篇文章主要為大家詳細(xì)介紹了Android利用屬性動(dòng)畫(huà)實(shí)現(xiàn)優(yōu)酷菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01
Android 根據(jù)手勢(shì)頂部View自動(dòng)展示與隱藏效果
這篇文章主要介紹了Android 根據(jù)手勢(shì)頂部View自動(dòng)展示與隱藏效果,本文給大家介紹非常詳細(xì)包括實(shí)現(xiàn)原理和實(shí)例代碼,需要的朋友參考下吧2017-08-08
android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條
本篇文章主要介紹了android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條,OkHttp是比較火的網(wǎng)絡(luò)框架,它支持同步與異步請(qǐng)求,支持緩存,可以攔截,更方便下載大文件與上傳文件的操作,有興趣的可以了解一下2017-07-07
Android仿知乎客戶端關(guān)注和取消關(guān)注的按鈕點(diǎn)擊特效實(shí)現(xiàn)思路詳解
這篇文章主要介紹了Android仿知乎客戶端關(guān)注和取消關(guān)注的按鈕點(diǎn)擊特效實(shí)現(xiàn)思路詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
Android側(cè)滑菜單之DrawerLayout用法詳解
今天小編就為大家分享一篇關(guān)于Android側(cè)滑菜單之DrawerLayout用法詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03

