1. 程式人生 > 其它 >線上直播系統原始碼,開屏首頁廣告點選跳過按鈕跳過倒計時

線上直播系統原始碼,開屏首頁廣告點選跳過按鈕跳過倒計時

線上直播系統原始碼,開屏首頁廣告點選跳過按鈕跳過倒計時實現的相關程式碼

<?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/ic_sp">
<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>

​主活動SpActivity.java

public class SpActivity extends AppCompatActivity implements View.OnClickListener{
private int recLen = 5;//跳過倒計時提示5秒
private TextView tv;
Timer timer = new Timer();
private Handler handler;
private Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//定義全屏引數
int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//設定當前窗體為全屏顯示
getWindow().setFlags(flag, flag);
setContentView(R.layout.activity_sp);
initView();
timer.schedule(task, 1000, 1000);//等待時間一秒,停頓時間一秒
/**
* 正常情況下不點選跳過
*/
handler = new Handler();
handler.postDelayed(runnable = new Runnable() {
@Override
public void run() {
//從閃屏介面跳轉到首介面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 5000);//延遲5S後傳送handler資訊
}
private void initView() {
tv = (TextView) findViewById(R.id.tv);//跳過
tv.setOnClickListener(this);//跳過監聽
}
TimerTask task = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() { // UI thread
@Override
public void run() {
recLen--;
tv.setText("跳過 " + recLen);
if (recLen < 0) {
timer.cancel();
tv.setVisibility(View.GONE);//倒計時到0隱藏字型
}
}
});
}
};
/**
* 點選跳過
*/
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv:
//從閃屏介面跳轉到首介面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
if (runnable != null) {
handler.removeCallbacks(runnable);
}
break;
default:
break;
}
}
}

在styles.xml中改樣式,沒有標題欄(Theme.AppCompat.Light.NoActionBar),程式碼:


<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

</style>

以上就是 線上直播系統原始碼,開屏首頁廣告點選跳過按鈕跳過倒計時實現的相關程式碼,更多內容歡迎關注之後的文章