So we're going to create two buttons.
One with the text load interstitial, and
one with the text
interstitial not ready.
Let's first look at the layout
file where these are defined.
So this is going to be in
the interstitial activity.
So we open the activity_interstitial
layout file here.
Here you can see a linear
layout that has two buttons.
The first button is our load button.
It has the text Load Interstitial.
And when we click on the button the
loadInterstitial method will be called.
The second button is the one
showing Interstitial Not Ready.
And when this button is called, the
showInterstitial method will be called.
And as you can see, I haven't
really hard coded the text here.
These are actually string
resources that we'll define in
our string resource file.
So if we look at the definition
of these constants,
we go into our Strings resource file.
The interstitial_load constant
is set to Load Interstitial.
The interstitial_not_ready constant
is set to Interstitial Not Ready.
I've also defined a constant called
interstitial_loading that I set to
Loading Interstitial.
We'll use that later in our code.
Here you can also see that we have
defined the interstitial_ad_unit_id.
This will be the ad unit id that
we use for our interstitial ad.
And as you can see,
I've hard coded it to this string here,
which is the string you can use
to display test interstitial ads.
Similar to this constant up here which
is the test ad unit id for banner ads.
All right, so
now when we have our layout file in
order, lets look at the actual code.
So we go into the interstitial
activity java file.
So first of all you can see that
we've added a member, mShowButton.
And in onCreate we call
our parent's onCreate.
Then, we set the content
view to the layout file
of the interstitial activity,
the one we just looked at.
We find the button using,
findViewById, providing the showButton
in the layout file as an argument.
And then we disable this button.
When the Load Interstitial
button is clicked, we,
again, disable the show button.
And then we change its text
to Loading Interstitial.
And, as you can see, this text is also
something we've defined in our resource
file, the interstitial_loading
resource we just looked at.
So we get this string resource
using getResources and getString.
And for now the show interstitial
callback will be empty.
We will add code to this callback later,
but as you can see, this callback
can't even be called right now because
this button is always disabled.
سننتقل إلى إنشاء زِرّين.
واحد باستخدام تحميل بيني للنص،
وآخر باستخدام نص بيني غير جاهز.
أولاً، لنلقي نظرة على ملف التخطيط
حيث يتم توضيح هذين الزرين.
وسوف يكون ذلك في النشاط البيني.
نفتح ملف تخطيط activity_interstitial هنا.
يمكنك رؤية تخطيط خطي لديه
زرين.
المفتاح الأول هو زر التحميل لدينا.
ولديه التحميل البيني للنص.
عند النقر على زر طريقة التحميل البيني
سوف يتم استدعائها.
الزر الثاني يعرض إعلان بيني
غير جاهز.
عند استدعاء هذا الزر، يتم استدعاء
طريقة عرض الفاصل
وكما تشاهدون، هنا يوجد نص ليس به
تعليمات برمجية مضمنة.
هذه بالفعل مصادر سلسلة
سوف نعرفها في
ملف مصادر سلسلة لدينا.
فإذا نظرنا إلى تعريف هذه الثوابت،
ننتقل إلى ملف مصادر سلسلة لدينا.
The interstitial_load ثابت مُعين
لتحميل إعلانات بينية.
interstitial_not_ready ثابت مُعين
للإعلانات البينية غير الجاهزة.
لقد عرفت أيضًا ثابت يُسمى interstitial_
loading مُعين
لتحميل الإعلانات البينية.
سنستخدم ذلك في تعليمية برمجية لدينا
لاحقًا.
أيضًا، يمكنك هنا مشاهدة أننا عرّفنا
interstitial_ad_unit_id.
سوف يكون ذلك وحدة الإعلان الذي نستخدمه
في إعلان بيني لدينا.
وكما تشاهدون، قمت بوضع تعليمة برمجية
إلى هذه السلسلة هنا،
وهذه السلسلة التي يمكنكم استخدامها لعرض
اختبار الإعلانات البينية.
مشابهة لهذا الثابت بالأعلى هنا وهواختبار
مُعرف وحدة الإعلان في إعلانات الشعار.
حسنًا،
عند توافق ملف التخطيط لدينا، لنلقي نظرة
على التعليمة البرمجية الفعلية.
سننتقل إلى ملف java للنشاط البيني.
وقبل كل شئ، يمكنك مشاهدة أننا أضفنا
عضو، طريقة عرض الزر.
وفي الإنشاء نستدعي إنشاء أصل لدينا.
بعد ذلك، نقوم بتعيين طريقة عرض المحتوى
إلى ملف تخطيط
النشاط البيني، الذي شاهدناه.
نعثر على استخدام الزر،
ونعثر على طريقة العرض بواسطة المُعرف،
مقدمًا زر العرض في ملف التخطيط كوسيطة.
وبعد ذلك، نقوم بتعطيل هذا الزر.
في حالة النقر على زر تحميل الإعلان البيني
نقوم بتعطيل زر العرض مرةً أخرى.
ثم نقوم بتغيير نص الزر إلى
تحميل الإعلان البيني.
وهذا النص أيضًا قد عرفناه في
ملف المصدر لدينا، interstitial_loading
مصدر شاهدناه للتو.
نحصل على مصدر سلسلة باستخدام "الحصول
على مصادر" و"الحصول على سلسلة".
والآن سوف يكون استدعاء عرض
الإعلان البيني فارغًا.
سنضيف تعليمة برمجية إلى هذا الاستدعاء
لاحقًا، ولكن كما تشاهدون، لا يمكن
طلب هذا الاستدعاء الآن لأن
هذا الزر مُعطل دائمًا.
그러므로 우리는 두 개의 버튼을 만들어보겠습니다.
하나는 틈새광고에 띄운 문구이고
다른 하나는 준비되지 않은 틈새과고 문구입니다.
첫째로 이들을 정의하는 지점에서 레이아웃 파일을 봅시다.
그러므로 이것이 간접 광고 활동이 됩니다.
그러므로 우리는 여기에서 틈새광고 활동으 하기 위해 만든 레이아웃 파일을 엽니다.
여기에 두 개의 버튼을 포함하는 직선 레이아웃을 볼 수 있습니다.
첫 번재 버튼은 로드 버튼입니다.
여기에 간섭 광고 위에 띄울 문구가 있습니다.
그리고 우리가 버튼을 클릭할 때, lodinterstitial 방식을 호출할 것입니다.
두 번째 버튼은 주비되지 않은 간접 광고를 보여줍니다.
그리고 이 버튼을 호출할 때, showInterstitial 방식을 호출할 것입니다.
우리가 보는 바와 같이, 저는 여기에서 문구를 정말 열심히 코드하지 앟았습니다.
이들은 실제로 우리가 스트링 자료 파일에서 정의할 스트링
리소스입니다.
그러므로 이들 상수의 정의를 본다면
우리는 스트링 리소스 파일을 보게 됩니다.
Interstitial_load 상수는 Load Interstitial을 설정합니다.
interstitial_not_ready 상수는 Interstitial Not Ready를 설정하게 합니다.
저는 Loading Interstitial을 설정한 ionterstitial_loading이라고 부르는 상수를
정의하였습니다.
우리는 저 코드를 이후에 사용할 것입니다.
여기에서 우리는 interstitia_ad_unit_id를 정의하였다는 사실을 볼 수 있습니다.
이것이 틈새 광고를 위해서 우리가 사용하는 광고 단위 아이디가 될 것입니다.
그리고 보시는 바와 같이 저는 여기 이 스트링을 열심히 코딩했습니다.
이것은 시험 틈새 광고를 전시하기 위해서 사용할 수 있는 스트링입니다.
바로 여기 이 상수과 비슷하지요. 이것은 배너 광고를 위한 시험 광고 단위 아이디입니다.
좋습니다. 그러면
이제 우리가 레이아웃 파일을 보았으니, 실제 코드를 봅시다.
그러므로 우리는 틈새 광고 활동 자바 파일을 봅니다.
그러므로 우선적으로 우리가 구성원을 추가하였다는 사실을 볼 수 있습니다. mShowButton이 그것입니다.
그리고 onCreate에서 우리는 페어런트의 onCreate를 부릅니다.
그 뒤에 우리는 틈새광고활동의 레이아웃 파일에 대한 내용 뷰를 설정합니다.
우리가 찾고있는 것입니다.
우리는 사용할 버튼을 발견했습니다.
findViewByID가 그것입니다. 우리는 논의로서 레이아웃 파일에서 showButton을 제공합니다.
그리고 그 뒤에 우리는 이 버튼을 사용하지 않습니다
Load Interstitial 버튼을 클릭하면 우리는
다시, 쇼 버튼을 사용하지 못합니다.
그리고 그 뒤에 우리는 Loading Interstitial에서 문구를 바꿉니다.
그리고 볼 수 있는바와 마찬가지로 이 문구는 우리의 리소스 파일에서 정의한 무언가입니다.
interstitial_loading resource를 우리가 볼 것입니다.
그러므로 우리는 이 스트링 자원을 얻고, getResources and getString을 사용합니다.
그리고 이제 틈새광고 콜백이 비어있다는 사실을 우리가 봅니다.
우리는 이후에 이 콜박에 코드를 더할 것이고, 그러나 볼 수 있는 바와 같이 이 콜백으로
바로 지금 호출을 할 수조차 없습니다. 왜냐하면 이 버튼이 언제나 사용할 수 없는 상태이기 때문입니다.
Vamos criar
dois botões.
Um com o texto "Load interstitial"
e outro com o texto
"Interstitial not ready".
Primeiro, vejamos o arquivo de layout
em que eles estão definidos.
Então, faremos isso
na atividade intersticial.
Por isso, abrimos
o arquivo de layout
"activity_interstitial" aqui.
Aqui, vemos um layout linear
que tem dois botões.
O primeiro botão
é nosso botão de carregamento.
Ele tem o texto "Load Interstitial".
E, quando clicarmos no botão,
o método "loadInterstitial"
será chamado.
O segundo botão é o que mostra
"Interstitial Not Ready".
Quando clicarmos nele,
o método "showInterstitial"
será chamado.
Como se vê, eu ainda não fixei
um texto aqui no código.
Na verdade,
são recursos de string
que definiremos
em nosso arquivo de recursos de string.
Assim, se verificarmos a definição
dessa constantes,
vamos para
nosso arquivo de recursos "Strings".
E a constante "interstitial_load"
está definida como "Load Interstitial".
E a constante "interstitial_not_ready"
está definida como "Interstitial Not Ready".
Também defini uma constante
chamada "interstitial_loading",
que defini como "Loading Interstitial".
Nós a usaremos mais adiante em nosso código.
Aqui, também vemos
que nós definimos
o "interstitial_ad_unit_id".
Isto será o ID de unidade do anúncio
que usaremos para nosso anúncio intersticial.
E, veja,
eu fixei esse valor nesta string aqui,
que é a string que pode ser usada
para exibir os anúncios intersticiais em nosso teste.
Da mesma forma que esta constante aqui,
que é o ID de unidade do anúncio
para o teste de anúncios em banners.
Certo,
agora, com nosso arquivo
de layout em ordem,
vejamos o código de fato.
Vamos para
o arquivo Java de atividade intersticial.
Em primeiro lugar, veja que
adicionamos um membro, "mShowButton".
E, em "onCreate", nós chamamos
o "onCreate" pai.
Depois, definimos a exibição
de conteúdo com o arquivo de layout
da atividade intersticial,
aquele que acabamos de ver.
Vemos que o botão
está usando "findViewById",
fornecendo "showButton"
no arquivo de layout como um argumento.
Vamos desabilitar esse botão.
Quando se clica no botão
"Load Interstitial",
mais uma vez, nós desabilitamos "ShowButton".
Em seguida, alteramos seu texto
para "Loading Interstitial".
Veja que
nós também definimos este texto
em nosso arquivo de recursos,
o recurso "interstitial_loading"
que acabamos de ver.
Por isso, vemos este recurso de string
usando "getResources" e "getString".
E, por enquanto, o retorno de chamada
"showInterstitial" estará vazio.
Vamos adicionar código
a este retorno de chamada mais tarde,
porém, veja que ele
sequer pode ser chamado agora
porque este botão
está sempre desabilitado.
接下来我们将创建两个按钮
一个具有文本“加载插播式广告”
而另一个具有文本“插播式广告未准备就绪”
首先我们看一下要定义这些内容的布局文件
这将包含在插播式广告 activity 中
在这里打开 activity_interstitial 布局文件
可以看到具有两个按钮的线性布局
第一个按钮是加载按钮
它的文本是“加载插播式广告”
单击该按钮时会调用 loadInterstitial 方法
第二个按钮用于显示“插播式广告未准备就绪”
单击该按钮时会调用 showInterstitial 方法
可以看到 我实际没有对文本进行硬编码
实际上 这些文本是我们将在字符串资源文件中
定义的字符串资源
如果要看一下这些常量的定义
可以进入字符串资源文件
interstitial_load 常量设置为“加载插播式广告”
interstitial_not_ready 常量设置为“插播式广告未准备就绪”
我还定义了名为 interstitial_loading 的常量
并将其设置为“正在加载插播式广告”
我们稍后将在代码中使用该常量
在这里 还可以看到我们已经定义了 interstitial_ad_unit_id
这是用于插播式广告的广告单元 id
可以看到 我已经在这里将其硬编码为这个字符串
可以使用该字符串显示测试插播式广告
与该常量相似 这是横幅广告的测试广告单元 id
好了
现在布局文件已就绪 我们看一下实际的代码
进入插播式广告 activityjava 文件
首先可以看到 我们已经添加成员 mShowButton
在 onCreate 中 我们调用父项的 onCreate
然后 将内容视图设置为我们刚刚看到的
插播式广告 activity 的布局文件
我们发现 在布局文件中
按钮使用 findViewById 提供 showButton 作为自变量
随后 我们禁用该按钮
单击“加载插播式广告”按钮时
我们再次禁用显示按钮
然后 将其文本更改为“正在加载插播式广告”
可以看到 该文本也是我们刚刚看过的
资源文件 interstitial_loading 中定义的内容
因此 我们使用 getResources 与 getString 获得该字符串资源
到现在为止 显示插播式广告回调还没有任何内容
我们稍后会将代码添加到该回调 但你可以看到
现在无法调用该回调 因为一直在禁用该按钮