I've implemented the action bar found here https://github.com/johannilsson/android-actionbar and it works beautifully. However, I've added a search button and can't get it to show the search dialog. I followed the Google's search dialog tutorial to set my project up, but the dialog just won't show up. Any help?
Manifest:
<activity android:name=".HomeActivity" android:label="Intelicase Mobile" android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity android:name=".SearchActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
<!-- this activity enables the search dialog to initiate searches in the SearchableActivity -->
<activity android:name=".OtherActivity">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
Action Bar setup:
ActionBar actBar = (ActionBar) findViewById(R.id.actionbar);
actBar.setTitle("Dashboard");
actBar.setHomeAction(new ActionBar.IntentAction(HomeActivity.this, intent, R.drawable.ic_title_home_default));
intent = new Intent().setClass(this, CaseEvidenceActivity.class);
actBar.addAction(new ActionBar.IntentAction(this, intent, R.drawable.ic_title_export_default));
intent = new Intent().setClass(this, OtherActivity.class);
actBar.addAction(new ActionBar.IntentAction(this, intent, R.drawable.ic_title_search_default));
OtherActivity:
public class OtherActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
onSearchRequested();
}
}
searchables.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="Intelicase Mobile"
android:hint="Search Intelicase" android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
Action Bar Setup
actionBar.addAction(new SearchMP());
private class SearchMP extends AbstractAction {
public SearchMP() {
super(R.drawable.title_search);
}
#Override
public void performAction(View view) {
onSearchRequested();
}
}
Related
My main activity needs to invoke a search and display search results. The search dialog does not appear when onSearchRequested() is called.
I have found similar questions and followed every detail (I think) but apparently I have something else wrong. Here are snips of my implementation.
Parts of AndroidManifest.xml
<application
android:label="#string/AppName"
android:launchMode="singleTop"
... >
<meta-data
android:name="android.app.default_searchable"
android:value=".main.MainActivity" />
<activity
android:name=".main.MainActivity"
android:launchMode="singleTop"
... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/deep_search" />
</activity>
...
</application>
deep_search.xml
<?xml version="1.0" encoding="utf-8"?>
<Searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/AppName"
android:hint="#string/search_deep_hint" >
</Searchable>
Parts of MainActivity:
public class MainActivity extends Activity implements ...
{
#Override
protected void onNewIntent (Intent intent)
{
setIntent(intent);
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
String query = intent.getStringExtra (SearchManager.QUERY);
// Do work using string
}
}
#Override
public boolean onOptionsItemSelected (MenuItem item)
{
int selectedId = item.getItemId();
switch (selectedId)
{
case ...:
case R.id.menu_search_deep:
boolean launched = onSearchRequested();
logI ("home page deep searched launched: " + launched); // log shows we got here
}
return true;
}
...
}
I have really tried everything I found on the internet and cannot find a solution.
I want to remove title bar from all of my activities, and my main activity to look like home activity screen on facebook. So, action bar with swiping, fragments and a search on the top. Iv done action bar with swiping and fragments right, but I cannot remove title bar for my search. Here is the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
initializeLayout();
}
public Lokal getLokal() {
return lokal;
}
public Context context(){
return getApplicationContext();
}
private void initializeLayout(){
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPageAdapter(getSupportFragmentManager());
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
viewPager.setAdapter(mAdapter);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
And here is my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="v.menadzeri" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:theme="#style/Theme.Sherlock.Light.NoActionBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<activity
android:name=".activities.Login"
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=".activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MainActiviy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SplashScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.ProfilActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ProfilActiviy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.LokalLayoutActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.LokalLayoutAct" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Thank you for your answer in advance.
http://i.stack.imgur.com/QGmEG.png
Need the Soundboard removed, whole thing and instead of that put search box.
It doesnt allow me to put images
Ok I'm incredibly frustrated I've been trying to get a SearchView to work for hours now with no luck. I checked out how to handle this and I found a sample project and the sample project works great. I then implement the same exact things in my project and bam I'm screwed. The intent won't fire. I don't understand why. I followed this
I have all my activities in an activity folder but removed the Search and Main one to see if that was the case... it's not. In my Search Results activity I'm handling the intent. It looks like this currently.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_result);
// get the action bar
ActionBar actionBar = getActionBar();
// Enabling Back navigation on Action Bar icon
actionBar.setDisplayHomeAsUpEnabled(true);
txtQuery = (TextView) findViewById(R.id.txtQuery);
handleIntent(getIntent());
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.search_result, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
/**
* Handling intent data
*/
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
txtQuery.setText("Search Query: " + query);
}
}
My Searchable XML looks like this.
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="#string/search_hint"
android:label="#string/app_name" />
For some reason the search hint is not appearing, Yet the string resource shows up and it's declared.
my options menu looks like this
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/search"
android:title="Search"
android:icon="#android:drawable/ic_search_category_default"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
<item android:id="#+id/Menu"
android:title="MENU"
android:showAsAction="collapseActionView|ifRoom"
/>
And my Manifest looks like this.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.MenuActivity"
android:label="#string/title_activity_menu"
android:theme="#style/IDME.Theme.Transparent" >
</activity>
<activity
android:name=".activities.CategoriesActivity"
android:label="#string/title_activity_categories" >
</activity>
<activity
android:name=".SearchResultActivity"
android:label="#string/title_activity_search_result"
>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
</application>
</menu>
And my Search View inflator looks like this.
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.options_menu, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}
I cannot for the life of me figure out what's going on, I followed both guides to a tee, I cannot see what's wrong. I've messed around with metadata and I just really can't see the problem anymore. I'm stuck
I, too, followed the exact same (official Android) guide Setting Up the Search Interface and was in the same boat as the OP #rubsnick.
Turns out, all that that needs to be tweaked is--
Change
<activity
android:name=".MainActivity"
android:label="#string/app_name"
>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Notice the <meta-data code! (specifically, android:name)
Also, no need to specify the searchable xml resource here... instead, do that in the SearchResultActivity activity, as shown below...
Lastly, Modify <activity for SearchResultActivity, like so:
<activity
android:name=".SearchResultActivity"
android:label="#string/title_activity_search_result" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
</activity>
The following SO thread does full justice as to why default_searchable and not searchable:
What's the difference between android.app.default_searchable and android.app.searchable meta-data?
your meta data is incorrect you must use:
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"
android:value="your package name of searchable activity.SearchResultActivity" />
I am creating a Jigsaw Puzzle application in android. I have created two activites, activity_jigsaw.xml and activity_level.xml. One activity is created by default (Displaying Hello World!) which I modified and created a new activity by following these steps:
File -> New -> Other -> Android Activity
But when I install the application these two files (and all other activities of the application) are installed as a separate project. But at the same time they are also interlinked. The Java code of the files as follows:
Jisaw.java file contains:
public class Jigsaw extends Activity {
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jigsaw);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_jigsaw, menu);
return true;
}
public void play(View v)
{
try
{
intent = new Intent(this, Level.class);
startActivity(intent);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Here Play is a function which is called when an image is clicked.
Level.java file contains:
public class Level extends Activity {
Intent intent;
String level = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_level, menu);
return true;
}
public void easy(View v)
{
level = "easy";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void medium(View v)
{
level = "medium";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void hard(View v)
{
level = "hard";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
}
Functions easy, medium and hard are called when a corresponding image is clicked.
Can somebody please tell me that what I am doing wrong?
Thanks in advance..
Here is the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maju.jigsawpuzzle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Jigsaw"
android:label="#string/title_activity_jigsaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Level"
android:label="#string/title_activity_level" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:label="#string/title_activity_play" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayBoard"
android:label="#string/title_activity_play_board" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You probably are defining android.intent.category.LAUNCHER intent category to all the activities in your AndroidManifest.xml, it creates an icon in the app launcher. Activities other than main should not have this intent filter.
Do something like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".JigSaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Level" />
<activity android:name=".Play" />
<activity android:name=".Playboard" />
</application>
EDIT:
As you just posted, you are indeed doing that, just remove the intent filter from other activities.
I have implemented the following code but my SearchActivity::OnCreate is not getting called. Can someone please tell me what I'm missing?
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kace.SearchTest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data android:name="android.app.default_searchable" android:value=".SearchActivity"/>
<activity
android:name=".Search_testActivity"
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=".SearchActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
<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>
/res/xml/searchable.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="#string/description" >
</searchable>
SearchActivity.java:
public class SearchActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
String query = intent.getStringExtra(SearchManager.QUERY);
int q;
q = 10;
}
}
#Override
protected void onNewIntent(Intent intent)
{
// TODO Auto-generated method stub
super.onNewIntent(intent);
}
}
Android guides explicitly says:
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
Which is in your case NOT TRUE. Because you don't want to search in MainActivity but in SearchableActivity. That means you should use this ComponentName instead of getComponentName() method:
ComponentName cn = new ComponentName(this, SearchableActivity.class);
searchView.setSearchableInfo(searchManager.getSearchableInfo(cn));
try this :
Update your AndroidManifest.xml as:
<activity
android:name=".Search_testActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:value=".SearchActivity"/>
</activity>
<activity android:name=".SearchActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
<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="#layout/searchable" />
</activity>
</application>
put searchable layout in layout/ instead of /res/xml/:
layout/searchable.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="#string/description"
android:searchMode="showSearchLabelAsBadge"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_form"
android:voicePromptText="#string/search_invoke"
android:searchSuggestSelection=" ? "
/>
For more working example see my answer in this post
And
You can download working example from SearchWidgetExample
Found the answer! In the onCreate method of my main activity (Not the search activity), I added the following lines:
SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
SearchView sv = (SearchView)findViewById(R.id.searchView1);
sv.setSearchableInfo(searchableInfo);
Try adding default_searchable setting under your "source" activity:
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
In short, you need default_searchable setting for the "source" activity and searchable setting for the "search result" activity (your SearchActivity class).