<small id='BKP4h'></small><noframes id='BKP4h'>

  • <legend id='BKP4h'><style id='BKP4h'><dir id='BKP4h'><q id='BKP4h'></q></dir></style></legend>
        <i id='BKP4h'><tr id='BKP4h'><dt id='BKP4h'><q id='BKP4h'><span id='BKP4h'><b id='BKP4h'><form id='BKP4h'><ins id='BKP4h'></ins><ul id='BKP4h'></ul><sub id='BKP4h'></sub></form><legend id='BKP4h'></legend><bdo id='BKP4h'><pre id='BKP4h'><center id='BKP4h'></center></pre></bdo></b><th id='BKP4h'></th></span></q></dt></tr></i><div id='BKP4h'><tfoot id='BKP4h'></tfoot><dl id='BKP4h'><fieldset id='BKP4h'></fieldset></dl></div>

        • <bdo id='BKP4h'></bdo><ul id='BKP4h'></ul>
      1. <tfoot id='BKP4h'></tfoot>

        自定义对话框上的 Admob 广告

        时间:2023-08-30

          <bdo id='so3ko'></bdo><ul id='so3ko'></ul>
            1. <small id='so3ko'></small><noframes id='so3ko'>

            2. <legend id='so3ko'><style id='so3ko'><dir id='so3ko'><q id='so3ko'></q></dir></style></legend>
                <tbody id='so3ko'></tbody>
            3. <tfoot id='so3ko'></tfoot>

              <i id='so3ko'><tr id='so3ko'><dt id='so3ko'><q id='so3ko'><span id='so3ko'><b id='so3ko'><form id='so3ko'><ins id='so3ko'></ins><ul id='so3ko'></ul><sub id='so3ko'></sub></form><legend id='so3ko'></legend><bdo id='so3ko'><pre id='so3ko'><center id='so3ko'></center></pre></bdo></b><th id='so3ko'></th></span></q></dt></tr></i><div id='so3ko'><tfoot id='so3ko'></tfoot><dl id='so3ko'><fieldset id='so3ko'></fieldset></dl></div>

                  本文介绍了自定义对话框上的 Admob 广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在应用上实施 Admob 广告.我想要做的是在自定义对话框上投放横幅广告.我已经尝试了所有方法,但找不到解决方案.

                  I am trying to implement Admob ads on app. What I want to do is to ad a banner ad on a custom Dialog. I have tried everything but can't find the solution.

                  我为对话框制作了一个自定义 xml.在xml上添加admob时,它不会运行.所以我尝试以编程方式进行.但仍然无法使其工作.

                  I have made a custom xml for the dialog. When adding admob on xml, it won't run. So I tried do it programmatically. But still can't make it work.

                  public void OnClickButton(View paramView)
                    {
                      int btn_id = paramView.getId();
                  
                         if (btn_id == R.id.hint_field)
                         {
                       //set up dialog
                             if (hint != null && hint.length()>0) {
                            final Dialog dialog = new Dialog(Activity.this);
                            dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
                  
                            //ad loading
                            dialog.setContentView(R.layout.custom_dialog);
                            RelativeLayout layout = (RelativeLayout)findViewById(R.id.dialog_l);
                            layout.addView(ad);
                            AdRequest r = new AdRequest();
                            ad.loadAd(r);
                  
                            dialog.setTitle("Σχετικά με την λέξη :");
                            dialog.setCancelable(true);
                  
                             //set up text
                            TextView text = (TextView) dialog.findViewById(R.id.hint_text);
                            text.setText(hint);
                  
                  
                  
                           //set up button
                             Button button = (Button) dialog.findViewById(R.id.Button01);
                             button.setOnClickListener(new OnClickListener() {
                             public void onClick(View v) {
                                     dialog.dismiss();
                                }
                            });
                  
                            // now that the dialog is set up, it's time to show it    
                             dialog.show();
                             dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
                       }
                     }   
                  

                  单击按钮时,我会显示一个自定义对话框.在我的 Activity 的 OnCreate 方法中,我制作了 adView

                  On a button click I display a custom Dialog. In the OnCreate method of my Activity I have made the adView

                    AdView  ad = new AdView(this, AdSize.BANNER, "a15xxxxxxxxxxx");
                  

                  我在:layout.addView(ad); 处得到 NullPointerException;

                  I get a NullPointerException at : layout.addView(ad);

                  有什么想法吗?

                  提前致谢!

                  推荐答案

                  问题解决了!我必须先给自定义对话框界面充气.下面的代码是工作代码!

                  Problem solved! I had to inflate the custom dialog interface first. The code below is the working code!

                   public void OnClickButton(View paramView)
                    {
                      int btn_id = paramView.getId();
                  
                         if (btn_id == R.id.hint_field)
                         {
                       //set up dialog
                             if (hint != null && hint.length()>0) {
                            final Dialog dialog = new Dialog(Activity.this, R.style.Theme_New);
                            dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
                            dialog.setContentView(R.layout.custom_dialog);
                  
                            LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            View main = inflater.inflate(R.layout.custom_dialog, null);
                            dialog.setContentView(main);
                            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                  
                            LinearLayout linear = (LinearLayout)main.findViewById(R.id.ad_layout);
                  
                                ad = new AdView(this, AdSize.IAB_MRECT, "a15xxxxxxxx");
                  
                  
                          AdRequest request = new AdRequest();
                          Set<String> keywords = new HashSet<String>();
                          keywords.add("game");
                          request.setKeywords(keywords);
                  
                            linear.addView(ad);
                            ad.loadAd(request);
                  
                            dialog.setTitle("Title :");
                            dialog.setCancelable(true);
                  
                             //set up text
                            TextView text = (TextView) dialog.findViewById(R.id.hint_text);
                            text.setText(hint);
                  
                  
                           //set up button
                             Button button = (Button) dialog.findViewById(R.id.Button01);
                             button.setOnClickListener(new OnClickListener() {
                             public void onClick(View v) {
                                     dialog.dismiss();
                                }
                            });
                  
                            // now that the dialog is set up, it's time to show it    
                             lp.width = width;
                             lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                             dialog.show();
                             dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
                             dialog.getWindow().setAttributes(lp);
                             dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
                             dialog.getWindow().getAttributes().height = LayoutParams.WRAP_CONTENT;
                       }
                     }    
                  }
                  

                  这篇关于自定义对话框上的 Admob 广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android:如何从警报对话框启动 Activity 下一篇:如何让主屏幕快捷方式启动对话框?

                  相关文章

                  最新文章

                  1. <legend id='aO0Kd'><style id='aO0Kd'><dir id='aO0Kd'><q id='aO0Kd'></q></dir></style></legend>

                    • <bdo id='aO0Kd'></bdo><ul id='aO0Kd'></ul>
                    1. <small id='aO0Kd'></small><noframes id='aO0Kd'>

                      <tfoot id='aO0Kd'></tfoot>
                    2. <i id='aO0Kd'><tr id='aO0Kd'><dt id='aO0Kd'><q id='aO0Kd'><span id='aO0Kd'><b id='aO0Kd'><form id='aO0Kd'><ins id='aO0Kd'></ins><ul id='aO0Kd'></ul><sub id='aO0Kd'></sub></form><legend id='aO0Kd'></legend><bdo id='aO0Kd'><pre id='aO0Kd'><center id='aO0Kd'></center></pre></bdo></b><th id='aO0Kd'></th></span></q></dt></tr></i><div id='aO0Kd'><tfoot id='aO0Kd'></tfoot><dl id='aO0Kd'><fieldset id='aO0Kd'></fieldset></dl></div>