Please dont mark as duplicate as I have viewed several other same question and those solution didnt worked for me.
category_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/category.search"
android:title="Search"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
Mainfest.xml
<activity android:name=".CategoryActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<meta-data android:name="android.app.default_searchable" android:value=".SearchResultsActivity" />
</intent-filter>
</activity>
<activity
android:name=".SearchResultsActivity"
android:label="#string/title_activity_search_results"
android:theme="#style/AppTheme.NoActionBar"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".CategoryActivity" />
</activity>
CategoryActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.category_menu, menu);
SearchView searchView = (SearchView) menu.findItem(R.id.category_search).getActionView();
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultsActivity.class)));
return true;
}
SearchResultsActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"Search Began");
setContentView(R.layout.search_results_activity);
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
Log.d(TAG, "Herer");
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
//use the query to search your data somehow
Log.d(TAG, query);
}
}
Searchable.xml under res/xml/
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="Recipe Search" />
you should add onQueryTextListener in searchView.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.category_menu, menu);
SearchView searchView = (SearchView) menu.findItem(R.id.category_search).getActionView();
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultsActivity.class)));
searchView..setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
startActivity(CategoryActivity.this, SearchResultActivity.class);
return true;
}
#Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return true;
}
android hint and label must both be of type "#String/..."
hardcoded text will prevent SearchResultActivity from starting.
if in searchable.xml not contain android:label, it doesn't start SearchResultActivity, make sure you add this code in searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name" ===================> can not contain empty strings
android:hint="Recipe Search" />
Related
I have two classes in two different files, one is MainActivity and the other one is SearchResultsActivity.
For some reason when i press the search button it doesn't start SearchResultsActivity, I'm assuming this because i put several breakpoints (even some at the beginning of the class) and the debugger doesn't seem to reach them.
MainActivity.Java
package myapp.myapp;
public class MainActivity extends ActionBarActivity {
private Toolbar toolbar;
ProgressBar theProgressBar;
TextView stInstTxt;
public void sendMessage(View view) {
Intent intent = new Intent(this, MainActivity.class);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search_element).getActionView();
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
return true;
}
#Override
public boolean onOptionsItemSelected (MenuItem item){
// Handle item selection
switch (item.getItemId()) {
case R.id.search_element:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//text view
stInstTxt = (TextView) findViewById(R.id.textView01);
//progress bar
theProgressBar = (ProgressBar) findViewById(R.id.progressBar01);
theProgressBar.setVisibility(View.INVISIBLE);
//toolbar
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
}
}
SearchResultsActivity.Java
package myapp.myapp;
public class SearchResultsActivity extends Activity{
TextView stInstTxt;
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
searchItems(query);
}
}
public void searchItems(String query) {
stInstTxt.append(query);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myapp.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="myapp.myapp.SearchResultsActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value="myapp.myapp.SearchResultsActivity"/>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#FFF9C4">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:paddingTop="70dp"
android:layout_height="wrap_content">
<TextView android:text="#string/help_text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView01"
android:scrollbars="vertical"
android:visibility="visible"/>
</RelativeLayout>
</RelativeLayout>
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/search_element"
android:orderInCategory="200"
android:title="#string/search_hint"
android:icon="#drawable/ic_search"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView">
</item>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
Could there be something wrong with AndroidManifest.xml?
After almost 6 hours of trying to implement this (starting with the android documentation as a guide), and trying dozens of different ways to do it, i feel i maybe could help someone else with a similar problem save some time, I came up to this tutorial
I read it all but what I ended up doing was downloading the code and comparing it with mine until i found that I was missing a couple of important things. The official android documentation is incomplete, and pretty much there was no way i could have came up with a solution without seeing a real and complete working example.
I'm having trouble creating the search feature for my application. I have followed various tutorials, followed the Android Docs, and other Stack Overflow answers with no success. I have the icon for the each in one activity (ContinentActivity.java) and when clicked the toolbar opens up a search window. However typing data does not register in the SearchResultsActivity. It is never created. Could this be because I am using a toolbar and a menu?
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_swell_alert_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity"/>
<activity
android:name=".SearchResultsActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<!-- to identify this activity as "searchable" -->
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.appcompat.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name=".ui.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.locations.LocationSelectionActivity"
android:label="#string/title_activity_location_selection"
android:noHistory="true"
android:parentActivityName=".ui.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
<activity
android:name=".ui.locations.ContinentActivity"
android:theme="#style/NoAnimationTheme"
android:label="#string/title_activity_continent"
android:parentActivityName=".ui.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
<!-- Children of Continent Activity. Each have search capabilities-->
<activity
android:name=".ui.locations.CountryActivity"
android:theme="#style/NoAnimationTheme"
android:label="#string/title_activity_country"
android:parentActivityName=".ui.locations.ContinentActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.locations.ContinentActivity" />
</activity>
<activity
android:name=".ui.locations.StateActivity"
android:theme="#style/NoAnimationTheme"
android:label="#string/title_activity_state"
android:parentActivityName=".ui.locations.CountryActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.locations.CountryActivity" />
</activity>
<activity
android:name=".ui.locations.SurfSpotActivity"
android:theme="#style/NoAnimationTheme"
android:label="#string/title_activity_surf_spot"
android:parentActivityName=".ui.locations.StateActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.locations.StateActivity" />
</activity>
</application>
SearchResultsActivity.java
public class SearchResultsActivity extends AppCompatActivity {
public static final String TAG = "SEARCH_RESULTS_ACTIVITY";
SearchResultsAdapter mSearchResultsAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(TAG, "onCreate");
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.v(TAG, "onNewIntent");
handleIntent(intent);
}
private void handleIntent(Intent intent) {
Log.v(TAG, "HANDLE INTENT");
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
showResults(query);
}
}
private void showResults(String query) {
// Query your data set and show results
// ...
Log.v(TAG, "Searching for " + query + "...");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.v(TAG, "onCreateOptionsMenu");
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_location, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()) );
return true;
}
This activities menu has the search icon
ContinentActivity.java
public class ContinentActivity extends AppCompatActivity {
private ArrayList<Continent> mContinents;
#Bind(R.id.recyclerView) RecyclerView mRecyclerView;
#Bind(R.id.toolBar) Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_selection);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
LocationDataSource dataSource = new LocationDataSource(this);
dataSource.test();
mContinents = dataSource.readContinents();
ContinentAdapter adapter = new ContinentAdapter(this, mContinents);
mRecyclerView.setAdapter(adapter);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_location, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
return super.onOptionsItemSelected(item);
}
}
menu_location.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
android:orderInCategory="200"
android:title="#string/action_settings"
android:icon="#drawable/ic_search_white_24dp"
appcompat:showAsAction="always"
appcompat:actionViewClass="android.widget.SearchView"/>
</menu>
tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
android:elevation="4dp"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark"
android:titleTextColor="#color/ColorText">
</android.support.v7.widget.Toolbar>
Seems you have missing call to associate SearchView with searchable info within the onCreateOptionsMenu() method? Quote from the training link http://developer.android.com/guide/topics/search/search-dialog.html
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
But since you are not using the same activity for search result, you cannot simply use getComponentName(), but to use new ComponentName(this, SearchResultsActivity.class)
I have checked and double checked my manifest according to the docs and other questions. I cannot understand why setSearchableInfo returns NullPointerException
MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
// current activity is not searchable activity
ComponentName cn = new ComponentName(this, SearchResultsActivity.class);
searchView.setSearchableInfo(searchManager.getSearchableInfo(cn));
return true;
}
AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="#string/title_main_activity">
<intent-filter>
<action android:name="com.csgiusa.treatmentmanager.csgitreatmentmanager.RoomEditDetailed" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.csgiusa.treatmentmanager.csgitreatmentmanager.MainActivity" />
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity" />
</activity>
<activity
android:name=".SearchResultsActivity"
android:label="#string/title_activity_search_results">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
Searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/app_name" >
</searchable>
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="#+id/search"
android:title="#string/search"
android:icon="#drawable/ic_search"
app:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
Are you using AppCompat and AppCompatActivity ? If yes, you should use the AppCompat version of SearchView (the one in the support.v7 package) and define it in your menu with app:actionViewClass instead of android:actionViewClass.
Then you retrieve it using:
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
i have been trying to figure out how to make a simple search button. I found this (Implementing SearchView in action bar) which i thought would help and i guess it did, i just cant figure out why there is an error here:
SearchableActivity.java
package com.ryan.buttonsimple;
import android.app.SearchManager;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;
public class SearchableActivity extends ActionBarActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) findItemById(R.id.search_view); //**HERE IS THE ERROR! "findItemById" and "search_view" "Cannot resolve method for both**
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_searchable, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
here is my searchable.xml file:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/search_hint">
</searchable>
And here is my AndroidManifest.xml File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ryan.buttonsimple" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchableActivity"
android:label="#string/title_activity_searchable" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
</manifest>
action bar not showing in main activity while the same code present for another activity and another thing action bar overflow not showing by list in right corner
image 1 : main activity with menu key pressed
image 2 : show message activity
code for main activity:
public class MainActivity extends ActionBarActivity {
EditText t;
public final static String sendMessageextra="com.example.example2.textmessage";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t=(EditText) findViewById(R.id.textmessage);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
public void sendMessage(View v){
Intent sendmessageintent=new Intent(this,showMessage.class);
String messagestring=t.getText().toString();
sendmessageintent.putExtra(sendMessageextra, messagestring);
startActivity(sendmessageintent);
}
}
show message activity:
public class showMessage extends Activity{
TextView t;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sendmessage);
t=(TextView) findViewById(R.id.showmessage);
showmessage();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return true;
}
public void showmessage(){
Intent intent=getIntent();
String message=intent.getStringExtra(MainActivity.sendMessageextra);
t.setText(message);
Log.i("Set New Text Box", "Text BOx");
}
}
activity main actions.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search Widget -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView"/>
<!-- Location Found -->
<item android:id="#+id/action_location_found"
android:icon="#drawable/ic_action_location_found"
android:title="#string/action_location_found"
android:showAsAction="never" />
<!-- Help -->
<item android:id="#+id/action_help"
android:icon="#drawable/ic_action_help"
android:title="#string/action_help"
android:showAsAction="never"/>
</menu>
android menifest file:
Activity Manifest File:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.example.example2.showMessage"
android:label="Show Message" android:parentActivityName="com.example.example2.MainActivity"/>
</application>
</manifest>
If you want to show the search icon in the right of the actionbar in every activity then just make a change in the actions.xml instead of android:showAsAction="ifRoom" change it to android:showAsAction="always"
ActionBar not showing
Do this in your oncreate()
ActionBar actionBar = getActionBar();
actionBar.show();
ActionBar overflow
there you can see your menu
To display menu, In your activity main actions.xml,
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_search"
android:showAsAction="always"
android:title="#string/action_search"
android:icon="#android:drawable/ic_action_search"
android:actionViewClass="android.widget.SearchView"/>
</menu>
Like this you need to do changes in main actions file