I want NativeExpressAdView on Exit dialog. Exit dialog is custom dialog created in app. code for custom dialog are below.
public void onBackPressed() {
System.out.println("IN ON BACK PRESSED:");
final Dialog dialog = new Dialog(SplashActivity.this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.exit_dialog);
LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View main = inflater.inflate(R.layout.exit_dialog, null);
dialog.setContentView(main);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
LinearLayout linear = (LinearLayout)main.findViewById(R.id.layoutAdd);
NativeExpressAdView mNativeExpressAdView = new NativeExpressAdView(this);
mNativeExpressAdView.setAdSize(new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT));
mNativeExpressAdView.setAdUnitId("ca-app-pub-8410399846074282/9976822052");
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
linear.addView(mNativeExpressAdView);
mNativeExpressAdView.loadAd(adRequestBuilder.build());
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.dialog_text);
text.setText("Are you sure you wants to exit ?? " + R.string.app_name);
Button dialogButton = (Button) dialog.findViewById(R.id.btnCancel);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
Button btnRateus = (Button) dialog.findViewById(R.id.btnRateus);
// if button is clicked, close the custom dialog
btnRateus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flags to intent.
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName())));
}
}
});
Button btnConfirm = (Button) dialog.findViewById(R.id.btnConfirm);
// if button is clicked, close the custom dialog
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
dialog.show();
}
Its not working directly so i was try to inflate NativeExpressAdview in Linearlayout but it not displayed in linearlayout too. Please help me on that ... Thank you in Advance !!
This is due to the AUTO_HEIGHT attribute as mentionned in the official native ad express documentation here :