【发布时间】:2013-05-08 18:50:53
【问题描述】:
Android 文档解释说,应用程序徽标在定义时会随处使用。但是当搜索视图展开时,会使用应用图标而不是应用徽标,当搜索视图处于展开状态时,我找不到显示应用徽标的方法。
以下是相关部分。
清单文件
<application
android:name="MyApp"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:logo="@drawable/app_logo"
android:theme="@style/Theme.MyTheme" >
searchable.xml(设置图标不会改变任何东西)
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:hint="@string/search_hint" >
</searchable>
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="@drawable/ic_search"
android:showAsAction="always|collapseActionView" />
活动代码
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
menu.findItem(R.id.menu_search).setActionView(searchView);
注意:我使用 ABS SearchView,但当我切换到默认 SearchView 时也会发生同样的事情。
编辑:为了清晰起见,我添加了一些屏幕截图。
在这里,我使用星形图像作为应用程序徽标,使用 android 图像作为应用程序图标。 第一个屏幕截图是活动的默认视图。 第二个是单击搜索按钮时的视图。 它显示的是 android 图像,而我希望它是明星图像。
【问题讨论】:
-
OP,您可能想检查 tkeunebr 的答案和相关评论。把那 1 行放在我的 onCreate 中,我/你的问题就消失了
标签: android android-actionbar actionbarsherlock