PreferenceActivityに広告を表示させるカスタマイズ

PreferenceActivityは画面全体をそれ自体が使うようになっているので、そのままでは広告の枠を設定したり、ボタンを付けたりということはできない。そこで、広告を表示させるカスタマイズ方法を紹介する。

src/package/TestPreferenceActivity.java

public class TestPreferenceActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);

res/layout/ad_preference.xml

Appc

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/base_layout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

//広告枠
<jp.co.cayto.appc.sdk.android.LinearFloatView
android:id=”@+id/floatview_1″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
ayout_gravity=”bottom”
appc_floatview_mode=”A”/>

</LinearLayout>

admob

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:ads=”http://schemas.android.com/apk/lib/com.google.ads”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
<com.google.ads.AdView
android:id=”@+id/adView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
ads:adSize=”BANNER”
ads:adUnitId=”キー”
ads:loadAdOnCreate=”true”
android:minHeight=”50dp” />

</LinearLayout>

res/xml/preference.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android” >
<PreferenceCategory android:title=”@string/cat_word_title”>
<EditTextPreference android:title=”@string/pref_word_title” android:key=”pref_word” android:summary=”@string/pref_word_summary” android:dialogTitle=”@string/pref_word_dialog”/>
</PreferenceCategory>

//広告枠を「android:layout」に挿入
<Preference android:selectable=”true” android:layout=”@layout/ad_preference”/>

</PreferenceScreen>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です