@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (mUnfoldableView.isUnfolded()) { inflater.inflate(R.menu.detail_bar, menu); } else { inflater.inflate(R.menu.main_bar, menu); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setIconifiedByDefault(true); int id = searchView .getContext() .getResources() .getIdentifier("android:id/search_close_btn", null, null); ((ImageView) Views.find(searchView, id)).setImageResource(R.drawable.ab_search_clear); int searchId = searchView .getContext() .getResources() .getIdentifier("android:id/search_mag_icon", null, null); // SearchView.SearchAutoComplete autoComplete = // (SearchView.SearchAutoComplete)ll3.getChildAt(0); // Drawable drawable= getResources().getDrawable(R.drawable.ic_action_search); // drawable.setBounds(0, 0, drawable.getMinimumWidth(), // drawable.getMinimumHeight()); ((ImageView) Views.find(searchView, searchId)).setImageResource(R.drawable.ic_action_search); int searchId2 = searchView .getContext() .getResources() .getIdentifier("android:id/search_button", null, null); ((ImageView) Views.find(searchView, searchId2)) .setBackgroundResource(R.drawable.ic_action_search); searchView.setSearchableInfo( searchManager.getSearchableInfo(getActivity().getComponentName())); try { Field searchField = SearchView.class.getDeclaredField("mSearchButton"); searchField.setAccessible(true); ImageView searchBtn = (ImageView) searchField.get(searchView); searchBtn.setImageResource(R.drawable.ic_action_search); searchField = SearchView.class.getDeclaredField("mSearchPlate"); searchField.setAccessible(true); // LinearLayout searchPlate = (LinearLayout)searchField.get(searchView); // Drawable drawable= // getResources().getDrawable(R.drawable.ic_action_search); // drawable.setBounds(0, 0, drawable.getMinimumWidth(), // drawable.getMinimumHeight()); // // ((TextView)searchPlate.getChildAt(0)).setCompoundDrawables(drawable,null,null,null); // searchPlate.setBackgroundResource(R.drawable.edit_text_bkg); } catch (NoSuchFieldException e) { Log.e(TAG, e.getMessage(), e); } catch (IllegalAccessException e) { Log.e(TAG, e.getMessage(), e); } } }
private void showcaseActionItem(ViewParent p, Class absAbv, int itemType, int actionItemId) { try { Field mAmpField = absAbv.getDeclaredField("mActionMenuPresenter"); mAmpField.setAccessible(true); Object mAmp = mAmpField.get(p); if (itemType == ITEM_ACTION_OVERFLOW) { // Finds the overflow button associated with the ActionMenuPresenter Field mObField = mAmp.getClass().getDeclaredField("mOverflowButton"); mObField.setAccessible(true); View mOb = (View) mObField.get(mAmp); if (mOb != null) setShowcaseView(mOb); } else { // Want an ActionItem, so find it Field mAmvField = mAmp.getClass().getSuperclass().getDeclaredField("mMenuView"); mAmvField.setAccessible(true); Object mAmv = mAmvField.get(mAmp); Field mChField; if (mAmv.getClass().toString().contains("com.actionbarsherlock")) { // There are thousands of superclasses to traverse up // Have to get superclasses because mChildren is private mChField = mAmv.getClass() .getSuperclass() .getSuperclass() .getSuperclass() .getSuperclass() .getDeclaredField("mChildren"); } else mChField = mAmv.getClass().getSuperclass().getSuperclass().getDeclaredField("mChildren"); mChField.setAccessible(true); Object[] mChs = (Object[]) mChField.get(mAmv); for (Object mCh : mChs) { if (mCh != null) { View v = (View) mCh; if (v.getId() == actionItemId) setShowcaseView(v); } } } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (NullPointerException npe) { throw new RuntimeException( "insertShowcaseViewWithType() must be called " + "after or during onCreateOptionsMenu() of the host Activity"); } }