aki*_*irk -1 android android-appcompat android-actionbar searchview
我在AppCompat Actionbar中包含了一个SearchView,但它的图标总是有阴影.
对于其他图标,我使用Android下载页面中没有阴影的图标,实际上我也尝试为SearchView直通分配图标android:icon="@drawable/ic_action_search"但不会更改图标.

我的研究告诉我,实际上ab_ic_search.png来自android-support-v7-appcompat.jar正在被使用而我android:icon="@drawable/ic_action_search"被忽略了.
我尝试了各种各样的方法,比如尝试替换图像onPrepareOptionsMenu(通过尝试查找ImageView)或通过自定义子类SearchView但无效.
任何想法如何解决?基本上我只想让我的图标统一,我是否必须为所有其他图标添加阴影?可能我无论如何都无法为那些"三个点"添加阴影?
感谢这篇博文,我设法构建了我的解决方案:
public boolean onCreateOptionsMenu(Menu menu) {
// the search view is in the mymenu.xml
inflater.inflate(R.menu.mymenu, menu);
// now that it is inflated we can get the item
MenuItem item = menu.findItem(R.id.action_find);
// and through it the actionview
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
Drawable searchIcon = getActivity().getResources().getDrawable(R.drawable.ic_action_search); // the new icon
// and now we search within the view for the "bad" image
ImageView collapsedSearchIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_button);
// and finally replace it
collapsedSearchIcon.setImageDrawable(searchIcon);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1888 次 |
| 最近记录: |