How do I put an admob adview in the settings screen for a live wallpaper?

后端 未结 6 1814
孤街浪徒
孤街浪徒 2020-12-12 23:21

I\'ve seen the Mario live wallpaper uses admob ads in the settings screen, but I haven\'t been able to do it myself. If I put the adview into the settings.xml like you would

6条回答
  •  抹茶落季
    2020-12-12 23:48

    Here's a simpler solution: Create a new preference type that displays a single ad. You can then include that preference type in the xml definition for your preferences to display one or more ads.

    Custom Preference Class:

    public class AdmobPreference extends Preference
    {
    
        public AdmobPreference(Context context) {
            super(context, null);
        }
    
        public AdmobPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected View onCreateView(ViewGroup parent) {
                //override here to return the admob ad instead of a regular preference display
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            return inflater.inflate(R.layout.admob_preference, null);
        }
    
    }
    

    XML Layout for AdmobPreference:

    
    
    
        
    
    

    And then you just add something like this into your preferences xml definition:

    
    
    
        
    
        ... other preferences ...
    
    

提交回复
热议问题