<-- Advertisement dialog layout -->
="1.0"="utf-8"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/adImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/ad1" />
</LinearLayout>
The code that you must implement in your main app's activity's OnCreate method prior to setContentView method invocation:
package com.epsilon.adapp;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AlertDialog.Builder m_myAdDlgBuilder =
new AlertDialog.Builder(this);
final View myAdView = this.getLayoutInflater().
inflate(R.layout.dialog_ad, null);
ImageView adImageView = myAdView.findViewById(R.id.adImageView);
adImageView.setImageDrawable(getDrawable(this.getResources().getIdentifier("ad" +
(new Random().nextInt(3) + 1), "drawable", getPackageName())));
m_myAdDlgBuilder.setView(myAdView);
m_myAdDlgBuilder.setPositiveButton("ok", null);
AlertDialog myAdDialog = m_myAdDlgBuilder.create();
myAdDialog.setCanceledOnTouchOutside(true);
m_myAdDlgBuilder.show();
setContentView(R.layout.activity_main);
}
}
Here's the link to the ready-to-use Android project:
https://nofile.io/f/F0j207xZbn7/AdApp.zip