Hi,
Yeah we found a solution.
I will have a look at it on Monday if you are still interested.
Lot of other things happened since that day :-)
Regard
Peter
Ch. de la Hulpe 181
1170 Brussels
![]()
![]()
![]()
![]()
![]()
ATTENTION: The information in this electronic mail message is private and confidential, and only intended for the addressee. Should you receive this message by mistake, you are hereby notified that any disclosure, reproduction, distribution or use of this message is strictly prohibited. Please inform the sender by reply transmission and delete the message without copying or opening it. Messages and attachments are scanned for all viruses known. Always scan attachments before opening them.
130107 Documentation Search ActionView theming
Steps
Code snippet
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getSupportMenuInflater().inflate(R.menu.activity_home, menu);
//Create the search view
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
//searchView.setQueryHint("Search for countries…");
/*
* Access searchable.xml configuration for SearchView
*/
SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
Log.w(TAG, "====> searchableInfo:" + searchableInfo.getHintId());
searchView.setSearchableInfo(searchableInfo);
/*
* Getting id for 'search_plate' - the id is part of generate R file,
* so we have to get id on runtime.
*/
// Android SearchView
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
int searchVoiceBtnId = searchView.getContext().getResources().getIdentifier("android:id/submit_area", null, null);
// Alternative access for ABS SearchView
//int searchPlateId = R.id.abs__search_plate;
// Getting the 'search_plate' LinearLayout.
View searchPlate = searchView.findViewById(searchPlateId);
// Setting background of 'search_plate' to earlier defined drawable.
searchPlate.setBackgroundResource(R.drawable.kp_searchview);
/*
* if existing, align VoiceButton background as well
*/
Log.w(TAG, "====> searchVoiceBtnId id:" + searchVoiceBtnId);
if (searchVoiceBtnId != 0) {
View searchVoiceBtn = searchView.findViewById(searchVoiceBtnId);
searchVoiceBtn.setBackgroundResource(R.drawable.kp_searchview);
}
menu.add("Search")
.setIcon(R.drawable.action_search)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
Kp_searchview.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/kp_sq_searchviewdefault" />
<item android:drawable="@drawable/kp_sq_searchviewlostfocus" />
</selector>
Screenshots and nine-patches are attached:
Kp_sq_searchviewdefault.9.png
Kp_sq_searchviewlostfocus.9.png
Result
<item
android:id="@+id/search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="@drawable/ic_action_search"
android:showAsAction="always"
android:title="@string/search"/>
Fragment :
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.search){
return getSherlockActivity().onSearchRequested();
}
return super.onOptionsItemSelected(item);
}