android启动时的广告

1.新建welecomeactivity.java

package com.example.dell.apps;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.example.dell.apps.MainActivity;
import com.example.dell.apps.R;

public class WelcomeActivity extends Activity {
    // 声明控件对象
    private TextView textView;
    //声明时间有多少;
    private int count = 5;
    private Animation animation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 下面的话就是去除标题的方法
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome);
        // 初始化控件对象textView
        textView = (TextView) findViewById(R.id.textView);
        animation = AnimationUtils.loadAnimation(this, R.anim.animation_text);
        handler.sendEmptyMessageDelayed(0, 1000);
    }
    //咱在写一个计算Welcome界面的广告时间结束后进入主界面的方法
    private int getCount() {
        count--;
        if (count == 0) {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }
        return count;
    }
    //进行一个消息的处理
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 0) {
                textView.setText(getCount()+"");
                handler.sendEmptyMessageDelayed(0, 1000);
                animation.reset();
                textView.startAnimation(animation);
            }
        };
    };
}

2.在res目录下新建anim文件夹,文件夹下新建animation_text.xml文件,文件中添加代码

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
 <alpha
  android:duration="1000"
  android:fromAlpha="0.0"
  android:toAlpha="1.0" />
 <scale
  android:duration="800"
  android:fromXScale="1.5"
  android:fromYScale="1.5"
  android:pivotX="50%"
  android:pivotY="50%"
  android:toXScale="1.0"
  android:toYScale="1.0" />
</set>

3.在activity_welcome.xml文件中添加代码:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@mipmap/welcome"/>  //自己选择图片
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="广告倒计时:"
            android:textColor="#ffffff"
            android:textSize="10sp" />
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="5"
            android:textColor="#ffffff"
            android:textSize="10sp" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="s"
            android:textColor="#ffffff"
            android:textSize="10sp" />
    </LinearLayout>
</FrameLayout>

ps:Androidmanifest.xml中需注意:

<intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

上述代码在哪个Activity中,哪个Activity就先启动

下面附上源码:https://pan.baidu.com/s/1pfYknrT9Vj3ocsk7zbT6Ww

提取密码:1psk

原文地址:https://www.cnblogs.com/gaoyukun/p/10253737.html

时间: 2024-07-31 09:05:32

android启动时的广告的相关文章

Android启动时闪一下黑屏或者白屏

1.设定主题,此主题为透明的,加入到res/values/styles.xml中: <style name="Theme.AppStartLoadTranslucent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle&qu

如何在android studio 1.0 启动时设置代理【解决WARN - ateSettings.impl.UpdateChecker - Connection failed.】

今天第一次用android studio,下了个比较新的1.0.1 linux版本,结果启动时老是出现以下错误: [ 6987] WARN - ateSettings.impl.UpdateChecker - Connection failed. Please check your network connection and try again. 百度了以下,都没找到可行方案,最后在google里找到了解决方案,在此记录下来,供大家参考. 方法1: 到android studio安装目录,打开

【Android端 APP 启动时长获取】启动时长获取方案及具体实施

一.什么是启动时长? 1.启动时长一般包括三种场景,分别是:新装包的首次启动时长,冷启动时长.热启动时长 冷启动 和 热启动 : (1)冷启动:当启动应用时,后台没有该程序的进程,此时启动的话系统会分配一个新的进程给应用. (2)热启动:程序的进程依然存在,启动时通过已有进程启动进入到Activity显示页面的,就是热启动,或者从Android官网来看我们获取到的其实是温启动时长,就是Activity不存在的情况. (3)新装包的启动时长: 新装包的启动时长,预估是最长的,并且在5.0以下及5.

WinXP SP3 下安装 Android SDK,模拟器启动时出现错误...

============问题描述============ WinXP SP3 下安装 Android SDK,模拟器启动时出现错误. 安装了两个版本的 Android SDK,都是一样的. installer_r23.0.2-windows.exe 和 installer_r22.6-windows.exe 请问怎么可以解决这个问题?多谢!!! ============解决方案1============ 这个自带的模拟器太慢,下一个bluestakes或genymotion吧 =========

Android App 启动时显示正在加载图片(源码)

微信.QQ.天天动听等程序,在打开时显示了一张图片,然后跳转到相关界面.本文实现这个功能,其实很简单.... 新建两个Activity,LoadingActivity,MainActivity,将LoadingActivity设置为android.intent.action.MAIN.使用TimerTesk,或者Thread将LoadingActivity显示几秒后跳转到MainActivity界面. LoadingActivity: new Timer().schedule(new Timer

android启动到kernel时log信息如下,出现重启现象

android启动到kernel时log信息如下,出现重启现象,请大神指导,谢谢 20160329_09:31:43[    2.164381]-(0)[0:swapper/0][HRTimer] 20160329_09:31:43[    2.164381] Occurs 0 times in last ISR duration 20160329_09:31:43[    2.164381] last fn:tick_sched_timer+0x0/0x80, dur:34461 ns (s:

Android 启动APP时黑屏白屏的三个解决方案

你会很奇怪,为什么有些app启动时,会出现一会儿的黑屏或者白屏才进入Activity的界面显示,但是有些app却不会如QQ手机端,的确这里要做处理一下.这里先了解一下为什么会出现这样的现象,其实很简单,简历一个简单的例子就可以理解了. 其实,黑屏或者白屏这里并不是不正常,而是还没加载到布局文件,就已经显示了window窗口背景,黑屏白屏就是window窗口背景.代码如下,可以自己写个小demo就理解了. @Override protected void onCreate(Bundle saved

android实现应用程序只有在第一次启动时显示引导界面

概述 SharedPreferences的使用非常简单,能够轻松的存放数据和读取数据.SharedPreferences只能保存简单类型的数据,例如,String.int等.一般会将复杂类型的数据转换成Base64编码,然后将转换后的数据以字符串的形式保存在 XML文件中,再用SharedPreferences保存. 使用SharedPreferences保存key-value对的步骤如下: (1)使用Activity类的getSharedPreferences方法获得SharedPrefere

Android应用程序启动时发生AndroidRuntime : ClassNotFoundException for Activity class的解决方法

在android应用程序启动时抛出下面异常导致启动失败:07-09 17:12:35.709: ERROR/AndroidRuntime(3866): Uncaught handler: thread main exiting due to uncaught exception 07-09 17:12:35.719: ERROR/AndroidRuntime(3866): java.lang.RuntimeException: Unable to instantiate activity Com