Is there a way to add an admob advert to a PreferenceActivity? How to?
There is some changes to P.Melch answer in Adpreference class is like below (because its not working with latest google play ads library):
public class AdPreference extends Preference {
public AdPreference(Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);}
public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
public AdPreference(Context context) {super(context);}
@Override
protected View onCreateView(ViewGroup parent) {
// this will create the linear layout defined in ads_layout.xml
View view = super.onCreateView(parent);
// the context is a PreferenceActivity
Activity activity = (Activity)getContext();
AdView adView = new AdView(getContext());
adView.setAdUnitId("");
adView.setAdSize(AdSize.BANNER);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
((LinearLayout)view).addView(adView);
return view;
}
}