Android Sherlock Action Bar - Styling SearchView, Share Intent Icon, homeAsUpIndicator

I’m using the Sherlock toolbar and I want to change the icon that appears for the home, from Dark to white.

But my theme needs Holo.Light. Is there a way to set a custom icon for this via Styles?

I use the following actions in my action bar

main_activity.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_search" android:actionViewClass="com.actionbarsherlock.widget.SearchView" android:icon="@drawable/ic_menu_search" android:showAsAction="always" android:title="Search"/> <item android:id="@+id/action_category" android:icon="@drawable/ic_menu_category" android:showAsAction="always" android:title="Category"/> <item android:id="@+id/action_sort" android:icon="@drawable/ic_menu_sort" android:showAsAction="always" android:title="Sort"> <menu> <item android:id="@+id/action_sort_dist_nf" android:icon="@android:drawable/ic_menu_search" android:title="Distance (Near-Far)"/> <item android:id="@+id/action_sort_dist_fn" android:icon="@android:drawable/ic_menu_search" android:title="Distance (Far-Near)"/> <item android:id="@+id/action_sort_alpha_az" android:icon="@drawable/ic_menu_sort_az" android:title="Alpha (AZ)"/> <item android:id="@+id/action_sort_alpha_za" android:icon="@drawable/ic_menu_sort_az" android:title="Alpha (ZA)"/> </menu> </item> </menu> 

activity_place.xml

 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_share" android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" android:icon="@drawable/ic_menu_share" android:showAsAction="always" android:title="Search"/> </menu> 

I want to create a search style and search icon. Just like the Share Intent icon.

enter image description hereenter image description hereenter image description here

+4
source share
1 answer

A custom theme like this.

 <style name="Theme.mTheme" parent="android:Theme.Holo.Light"> <item name="android:homeAsUpIndicator">@drawable/image_with_whitecolorarrow</item> <item name="homeAsUpIndicator">@drawable/image_with_whitecolorarrow</item> </style> 

For custom search:

Define the menu in the menu folder

 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/searchIcon" android:actionLayout="@layout/search_icon_actionview" android:icon="@drawable/search_icon" android:showAsAction="ifRoom|collapseActionView" android:title="Search"/> </menu> 

searchIcon you can use your own icon. But there must be the correct size of the menu items in the action bar.

specify your custom search, i.e. ..., search_icon_actionview.xml

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="5dp" android:orientation="vertical" > <ImageView android:id="@+id/search_image" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:clickable="true" android:contentDescription="Search icon" android:paddingLeft="5dp" android:paddingRight="5dp" android:src="@drawable/search_icon" /> <AutoCompleteTextView android:id="@+id/search_editText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toLeftOf="@id/search_image" android:background="@drawable/rounded_corners_white" android:hint="Search" android:imeOptions="actionSearch" android:padding="5dp" android:singleLine="true" android:textColor="@color/text_dark_grey" android:textColorHint="@color/text_light_grey" android:textSize="20dp" /> </RelativeLayout> 

enter image description here

the search icon and the call icon are custom images that I made using the photo store.

Action Code:

 @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.searchIcon: mEtSearchbar.clearFocus(); (new Handler()).postDelayed(new Runnable() { public void run() { mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0)); } }, 100); return true; default: return super.onOptionsItemSelected(item); } } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.your_menu, menu); mSearchbar = (MenuItem) menu.findItem(R.id.searchIcon); View actionview = mSearchbar.getActionView(); mEtSearchbar = ((AutoCompleteTextView) actionview .findViewById(R.id.search_editText)); final ImageView searchImage = ((ImageView) actionview .findViewById(R.id.search_image)); searchImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String s = mEtSearchbar.getText().toString(); Intent intent = new Intent(CurrentActivity.this, SearchActivity.class); intent.putExtra("search_string", s); startActivity(intent); } }); mEtSearchbar .setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { searchImage.performClick(); return true; } return false; } }); super.onCreateOptionsMenu(menu, inflater); } 
+4
source

All Articles