title: How to add remove ads button in action bar in android studio?
body: <p>So, basically, I want to add a Remove ads button in my action bar which would on click open a paid version of my app in the play store.</p>
  <p>I have made the design pretty much but don't know how to implement it in code.</p>
  <p><a href="https://i.stack.imgur.com/VzMgW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VzMgW.png" alt="Design of the action bar" /></a></p>
  <p>I would be thankful to anyone who could teach me how to do it.</p>
  <p>Here is my code;</p>
  <p>public class MainActivity extends AppCompatActivity implements MyAsync.MyAsyncInterface, SwipeRefreshLayout.OnRefreshListener {</p>
  <pre><code>// Log
  private final String TAG = getClass().getSimpleName();
  
  // Constants
  public static final String EXTRA_DISABLE_NOTIFICATION = &quot;disable_notification&quot;;
  
  // Layout
  private View rootView;
  private MySwipeRefreshLayout swipeRefreshLayout;
  private InfoView infoView;
  
  // Catalog
  private CatalogAdapter catalogAdapter;
  private Catalog catalog;
  
  // Broadcast listener
  private final IntentFilter broadcastFilter = new IntentFilter(SyncManager.ACTION_SYNC);
  private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent != null) {
              int result = intent.getIntExtra(SyncManager.EXTRA_RESULT, SyncManager.RESULT_FAIL);
              swipeRefreshLayout.setRefreshing(false); // Stop refresh layout
              if (result == SyncManager.RESULT_SUCCESS) {
                  // Reload local content
                  if (loadLocalContent()) {
                      refreshList();
                  } else {
                      // This error is very unlikely to happen
                      showCatalogDownloadError();
                  }
              } else if (result == SyncManager.RESULT_TIMEOUT) {
                  // Connection timeout
                  showTimeoutError();
              } else {
                  // Catalog sync failed
                  showCatalogDownloadError(); // Show catalog download error
              }
          }
      }
  };
  
  private Context context;
  private Uri imageUri;
  
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      context = this;
  
      final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
  
      // Layout
      rootView = findViewById(R.id.main_container);
      GridView catalogList = findViewById(R.id.catalog_grid);
      swipeRefreshLayout = (MySwipeRefreshLayout) rootView;
      infoView = findViewById(R.id.info_view);
  
      // Swipe down refresh
      swipeRefreshLayout.setOnRefreshListener(this);
      swipeRefreshLayout.setSwipeableChildren(R.id.catalog_grid);
  
      // Catalog list
      catalogAdapter = new CatalogAdapter(this);
      catalog = new Catalog();
      catalogList.setAdapter(catalogAdapter);
      catalogList.setOnItemClickListener(catalogItemClickListener);
  
      // Before anything check if the sensors are available
      boolean checkSensors = sharedPreferences.getBoolean(PREF_CHECKSENS, PREF_CHECKSENS_DEFAULT);
      if (!Utils.sensorsAvailable(this) &amp;&amp; checkSensors) {
          new AlertDialog.Builder(context)
                  .setTitle(R.string.main_dialog_nosensor_title)
                  .setMessage(R.string.main_dialog_nosensor_message)
                  .setNegativeButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          sharedPreferences.edit().putBoolean(PREF_CHECKSENS, false).apply();
                          dialog.dismiss();
                      }
                  })
                  .show();
      }
  
      infoView.show(R.string.main_info_empty_title, R.string.main_info_empty_message);
  }
  
  @Override
  protected void onResume() {
      super.onResume();
  
      // Register broadcast listener
      registerReceiver(broadcastReceiver, broadcastFilter);
  
      // Check if refresh is running without service
      if (swipeRefreshLayout.isRefreshing() &amp;&amp; !SyncManager.isRunning()) {
          swipeRefreshLayout.setRefreshing(false);
      }
  
      // Load catalog if available
      loadLocalContent();
      refreshList();
  
      // Check if catalog is expired
      InternalData internalData = new InternalData(this);
      long lastTimestamp = internalData.readLong(LD_TIMESTAMP, 0);
      long delta = getTimestamp() - lastTimestamp;
  
      if (delta &lt; 0 || delta &gt; T_CATALOG_EXPIRATION || catalog.size() == 0) {
          // Catalog has expired download
          Log.d(TAG, &quot;Catalog has reached expiration&quot;);
          loadRemoteContent();
      } else {
          Log.d(TAG, &quot;Catalog is still valid!&quot;);
      }
  }
  
  
  @Override
  protected void onPause() {
      super.onPause();
  
      unregisterReceiver(broadcastReceiver);
  }
  
  // Download Listener
  @Override
  public void onCompleted(int id, Bundle extra) {
      if (id == WallpaperDownloader.ID) {
          CatalogItem downloadedItem = extra.getParcelable(WallpaperDownloader.EXTRA_CATALOG_ITEM);
          startSetActivity(downloadedItem);
          refreshList(); // refresh list for downloaded icon
      }
  }
  </code></pre>