我在三星设备上有一个奇怪的行为(Galaxy S4,Galaxy Note,......)。在我们的应用程序中,我们有一个带有搜索界面的主题Actionbar(使用ActionbarCompat)。基本上我们遵循这里的教程:http://developer.android.com/guide/topics/search/search-dialog.html
这是我们的Actionbar的默认外观,它可以正常工作:
此外,如果我触摸搜索图标,主题也会应用并且效果很好:
但如果我长按三星设备的菜单按钮,搜索将以默认主题打开:
我已经在我们的(自定义)-Application类中添加了主题,但没有出现任何更改。
@Override
public void onCreate() {
super.onCreate();
setTheme(R.style.ClassicTheme);
}
我怎样才能避免这种奇怪的行为?我必须在我们的样式中添加一些东西吗? 这是我的基本主题:
<style name="ClassicTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="themeIdentifier">classic</item>
<item name="android:windowBackground">@color/grey_default</item>
<item name="popupMenuStyle">@style/ClassicTheme.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">
@style/ClassicTheme.PopupMenuTextAppearanceLarge
</item>
<item name="textAppearanceSmallPopupMenu">
@style/ClassicTheme.PopupMenuTextAppearanceSmall
</item>
<item name="android:popupMenuStyle">@style/ClassicTheme.PopupMenu</item>
<item name="actionBarSearchIcon">@drawable/ic_classic_menu_search</item>
<item name="actionBarSearchBackground">@drawable/textfield_classic_ab</item>
<item name="actionBarToggler">@drawable/ic_classic_menu_menu_left</item>
<item name="android:actionBarStyle">@style/ClassicTheme.ActionBar</item>
<item name="android:dropDownListViewStyle">@style/ClassicTheme.DropDownListView</item>
<item name="dropDownListViewStyle">@style/ClassicTheme.DropDownListView</item>
<item name="android:actionDropDownStyle">@style/ClassicTheme.DropDownNav</item>
<item name="android:actionBarWidgetTheme">@style/ClassicTheme.Widget</item>
<item name="android:actionOverflowButtonStyle">@style/ClassicTheme.OverFlow</item>
<item name="android:actionBarItemBackground">@drawable/selector_classic_simple_fast</item>
<item name="android:spinnerItemStyle">@style/ClassicTheme.SpinnerItemStyle</item>>
</style>
<style name="ClassicTheme.SpinnerItemStyle" parent="@android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ClassicTheme.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/grey_darker</item>
<item name="android:backgroundStacked">@color/grey_darker</item>
<item name="android:backgroundSplit">@color/grey_darker</item>
<item name="android:progressBarStyle">@color/grey_darker</item>
</style>
<style name="ClassicTheme.ListPopupMenu" parent="@style/Widget.AppCompat.ListPopupWindow">
<item name="android:popupBackground">@drawable/bg_classic_menu_dropdown</item>
</style>
<style name="ClassicTheme.DropDownListView" parent="@style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">@drawable/selector_classic_simple</item>
<item name="android:divider">@color/grey_divider</item>
<item name="android:dividerHeight">1dp</item>
</style>
<!--<item name="android:background">@drawable/spinner_background_ab_ClassicTheme</item>-->
<style name="ClassicTheme.DropDownNav" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">@drawable/selector_classic_spinner_ab</item>
<item name="android:popupBackground">@drawable/bg_classic_menu_dropdown</item>
<item name="android:dropDownSelector">@drawable/selector_classic_simple</item>
<item name="android:textColor">@android:color/white</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="ClassicTheme.Widget" parent="@style/Theme.AppCompat">
<item name="android:popupMenuStyle">@style/ClassicTheme.PopupMenu</item>
<item name="android:dropDownListViewStyle">@style/ClassicTheme.DropDownListView</item>
<item name="searchViewAutoCompleteTextView">@style/ClassicTheme.SearchViewStyle</item>
<item name="textAppearanceSearchResultSubtitle">@style/ClassicTheme.SearchSuggestionSubtitleStyle</item>
</style>
<style name="ClassicTheme.OverFlow" parent="@style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_classic_menu_overflow</item>
</style>
<style name="ClassicTheme.PopupMenu" parent="@style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@drawable/bg_classic_menu_dropdown</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ClassicTheme.PopupMenuTextAppearanceSmall" parent="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ClassicTheme.PopupMenuTextAppearanceLarge" parent="@style/TextAppearance.AppCompat.Widget.PopupMenu.Large">
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
更新21.07.2014:我尝试在我的风格中添加actionModeBackground-attribute:
<item name="actionModeBackground">@drawable/cab_background_top_example</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_example</item>
但是如果我在列表视图中进行选择,这只会改变操作栏的外观。长按菜单按钮可将操作栏保持为白色。
此外,我在Android search_bar.xml资源中调查了一段时间。 (https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/layout/search_bar.xml) 在这个文件中,后台将由actionModeBackground-Attribute配置,但我不知道为什么这在我的特殊情况下不起作用。
答案 0 :(得分:1)
我最终通过覆盖startSearch(...) - Activity类的方法解决了这个问题,如果尚未打开则以编程方式展开Search-MenuItem。
@Override
public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
boolean globalSearch) {
// menuItemSearch-class attribute will be set up in onCreateOptionsMenu(...)
if (menuItemSearch == null || globalSearch) {
super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
return;
}
if (!menuItemSearch.isActionViewExpanded()) {
menuItemSearch.expandActionView();
}
}