Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This answer describes how to use the new ActionBarCompat library (July 2013).</p> <p>In <strong>Android Studio</strong>, open <code>build.gradle</code> and add this:</p> <pre><code>dependencies { compile 'com.android.support:appcompat-v7:18.0.+' } </code></pre> <p>In <strong>Eclipse</strong>, create a <a href="http://developer.android.com/tools/support-library/setup.html#libs-with-res" rel="noreferrer">library project</a> based on the code in <code>sdk\extras\android\support\v7\appcompat</code> and add it to your project.</p> <p>Activities have to extend <code>ActionBarActivity</code>.</p> <pre><code>import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; import android.support.v7.app.ActionBar; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity { ActionBar ab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ab = getSupportActionBar(); ab.setTitle("Test"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); return super.onCreateOptionsMenu(menu); } } </code></pre> <p>Themes have to be (or extend) one of the <code>Theme.AppCompat</code> themes, for example: </p> <pre><code>&lt;activity android:theme="@style/Theme.AppCompat.Light" ... /&gt; </code></pre> <p>Source: <a href="http://gmariotti.blogspot.de/2013/07/how-to-add-actionbarcompat-to-your.html" rel="noreferrer">How to add ActionBarCompat to your project</a>, blog post by Gabriele Mariotti</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload