Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

java - Show Native Ad OnBackpressed

I'm trying to show a Facebook Audience Network Native Ad onBackPressed i have added all the Layouts but i don't know how to implement it and this is my OnBackPressed code :

override fun onBackPressed() {
    AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle("Closing")
            .setMessage("Are you sure you want to Exit?")
            .setPositiveButton("Yes", DialogInterface.OnClickListener { dialog, which -> finish() })
            .setNegativeButton("No", null)
            .show()
}

i Want to implement a Native Facebook Audience Network Ad on the Dialog i have Created the Native Ad Layouts as Described Here : https://developers.facebook.com/docs/audience-network/guides/ad-formats/native/android

But i really don't know how to do this , Can you help me with this Please

This is a Screenshot of the OnBackPressed Dialog

Screenshot : When i want native ad to be shown

Thank you

question from:https://stackoverflow.com/questions/65831771/show-native-ad-onbackpressed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use .setView() to change the dialog layout.

It would look something like this:

public void onBackPressed() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle("Closing")
            .setView(R.layout.your_custom_layout)
            .setPositiveButton("Yes", DialogInterface.OnClickListener { dialog, which -> finish() })
            .setNegativeButton("No", null);

    AlertDialog dialog = builder.create();
    dialog.show();

    //Here you can use dialog.findViewById()
}

Sorry I don't know Kotlin, but it will be similar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...