In my app I have a AdView
object and Float button in a LinearLayout
(Vertical). And I want when the user buys the in-app-purchase "Remove ads" to remove the AdView
object from the xml so the FAB button take its place. Like this:
no ads:
How can I do that ? That is my xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/myMainRelativeLayout"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar">
</include>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:clickable="true"
android:background="?android:selectableItemBackground"
android:id="@+id/recyclerView"
android:layout_below="@+id/tool_bar"
/>
<TextView android:id="@+id/list_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Shopping Items yet"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="100"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<com.software.shell.fab.ActionButton
android:id="@+id/buttonFloat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:layout_gravity="center"
fab:show_animation="@anim/fab_roll_from_down"
fab:hide_animation="@anim/fab_roll_to_down"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
This is my code that removes the adview:
mIsRemoveAdds = inventory.hasPurchase(SKU_REMOVE_ADDS);
if(!mIsRemoveAdds) {
Toast.makeText(MainActivity.this,"no premium",Toast.LENGTH_LONG).show();
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}else{
if(mAdView != null) {
mAdView.setVisibility(View.GONE);
}
Toast.makeText(MainActivity.this,"premium",Toast.LENGTH_LONG).show();
}