java进入下一个_java - 当我按下按钮时,它应该转到下一个活动,但它会进入主屏幕 - SO中文参考 - www.soinside.com...

当我按下按钮时它应该转到下一个活动,但它会进入主屏幕。我添加横幅广告代码时遇到的这个问题。

Button在XML代码中命名为startbtn,在Java代码中命名为btnclk1。我在Android Studio中做这个项目。

XML code:

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:ads="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/splashscr"

tools:context=".SplashScreen">

android:id="@+id/startbtn2"

android:layout_width="85dp"

android:layout_height="32dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:background="@android:color/black"

android:text="Show Ad"

android:textColor="@android:color/white"

android:textSize="18sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.625" />

android:id="@+id/imageView"

android:layout_width="239dp"

android:layout_height="221dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.503"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.287"

app:srcCompat="@drawable/criclive" />

android:id="@+id/imageView3"

android:layout_width="288dp"

android:layout_height="20dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.507"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="1.0"

app:srcCompat="@drawable/credits" />

android:id="@+id/startbtn"

android:layout_width="85dp"

android:layout_height="32dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:background="@android:color/black"

android:text="Start"

android:textColor="@android:color/white"

android:textSize="18sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.559" />

android:id="@+id/adView"

android:layout_width="325dp"

android:layout_height="50dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.0"

ads:adSize="BANNER"

ads:adUnitId="ca-app-pub-8972808858904277/7753758329"/>

Java代码:

package com.airobotfyp.livecricket;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import com.google.android.gms.ads.AdListener;

import com.google.android.gms.ads.AdRequest;

import com.google.android.gms.ads.AdSize;

import com.google.android.gms.ads.AdView;

import com.google.android.gms.ads.InterstitialAd;

import com.google.android.gms.ads.MobileAds;

public class SplashScreen extends AppCompatActivity {

private InterstitialAd mInterstitialAd;

private AdView mAdView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_splash_screen);

Button btnclk1 = (Button) findViewById(R.id.startbtn);

Button btnclk2 = (Button) findViewById(R.id.startbtn2);

MobileAds.initialize(this, "ca-app-pub-8972808858904277~8136901702");

mAdView = findViewById(R.id.adView);

AdRequest adRequest = new AdRequest.Builder().build();

mAdView.loadAd(adRequest);

AdView adView = new AdView(this);

adView.setAdSize(AdSize.BANNER);

adView.setAdUnitId("ca-app-pub-8972808858904277/7753758329");

mAdView.setAdListener(new AdListener() {

@Override

public void onAdLoaded() {

// Code to be executed when an ad finishes loading.

}

@Override

public void onAdFailedToLoad(int errorCode) {

// Code to be executed when an ad request fails.

}

@Override

public void onAdOpened() {

// Code to be executed when an ad opens an overlay that

// covers the screen.

}

@Override

public void onAdLeftApplication() {

// Code to be executed when the user has left the app.

}

@Override

public void onAdClosed() {

// Code to be executed when the user is about to return

// to the app after tapping on an ad.

}

});

//full

mInterstitialAd = new InterstitialAd(this);

mInterstitialAd.setAdUnitId("ca-app-pub-8972808858904277/3431369930");

mInterstitialAd.loadAd(new AdRequest.Builder().build());

mInterstitialAd.setAdListener(new AdListener() {

@Override

public void onAdClosed() {

// Load the next interstitial.

mInterstitialAd.loadAd(new AdRequest.Builder().build());

}

});

mInterstitialAd.setAdListener(new AdListener() {

@Override

public void onAdLoaded() {

// Code to be executed when an ad finishes loading.

}

@Override

public void onAdFailedToLoad(int errorCode) {

// Code to be executed when an ad request fails.

}

@Override

public void onAdOpened() {

// Code to be executed when the ad is displayed.

}

@Override

public void onAdLeftApplication() {

// Code to be executed when the user has left the app.

}

@Override

public void onAdClosed() {

// Code to be executed when when the interstitial ad is closed.

}

});

btnclk1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (mInterstitialAd.isLoaded()) {

mInterstitialAd.show();

} else {

Log.d("TAG", "The interstitial wasn't loaded yet.");

}

Intent mainIntent = new Intent(SplashScreen.this,Menu.class);

startActivity(mainIntent);

}

});

btnclk2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (mInterstitialAd.isLoaded()) {

mInterstitialAd.show();

} else {

Log.d("TAG", "The interstitial wasn't loaded yet.");

}

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值