Created
November 20, 2013 09:40
-
-
Save ishitcno1/7560443 to your computer and use it in GitHub Desktop.
A Preference to show admob banner ads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.content.Context; | |
import android.preference.Preference; | |
import android.util.AttributeSet; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.LinearLayout; | |
import com.google.ads.AdRequest; | |
import com.google.ads.AdSize; | |
import com.google.ads.AdView; | |
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) { | |
parent.setPadding(0, 0, 0, 0); | |
View view = super.onCreateView(parent); | |
Activity activity = (Activity)getContext(); | |
AdView adView = new AdView(activity, AdSize.BANNER, "admob publisher id"); | |
((LinearLayout)view).addView(adView); | |
AdRequest request = new AdRequest(); | |
adView.loadAd(request); | |
return view; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment