ActionBarSherlock spinner not selectable ins ActionBar - Theme related - android

Some users of my application are experiencing a weird problem when using my application in landscape mode. I am using actionbarsherlock and have set the navigation mode to tabs (using ActionBar.NAVIGATION_MODE_TABS).
Some users are finding when launching the app in portrait and then rotating the device the actionbar shows a spinner list rather than the tabs (which apparently is expected behaviour). The problem is the spinner is not selectable.
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.addTab(bar.newTab().setText("Deals").setTabListener(this),false);
bar.addTab(bar.newTab().setText("Vouchers").setTabListener(this),false);
bar.addTab(bar.newTab().setText("Freebies").setTabListener(this),false);
EDIT
Just discovered it is related to my custom theme. Changing the theme to the default Sherlock.Light makes the spinner selectable. The custom theme is shown below.
<!-- Variation on the Holo Light theme that styles the Action Bar -->
<style name="DealPadTheme" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:selectableItemBackground">#drawable/ad_selectable_background</item>
<item name="actionBarItemBackground">#drawable/ad_selectable_background</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabStyle</item>
<item name="actionBarTabStyle">#style/MyActionBarTabStyle</item>
<item name="android:actionBarStyle">#style/Widget.ActionBar</item>
<item name="actionBarStyle">#style/Widget.ActionBar</item>
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:actionDropDownStyle">#style/MySpinner</item>
<item name="actionDropDownStyle">#style/MySpinner</item>
<item name="android:activatedBackgroundIndicator">#drawable/selectable_list_item</item>
<item name="activatedBackgroundIndicator">#drawable/selectable_list_item</item>
<item name="android:listSelector">#style/MyListView</item>
</style>
<style name="MyListView" parent="#android:style/Widget.ListView">
<item name="android:listSelector">#drawable/list_arrow_selected_holo</item>
</style>
<!-- style for the tabs -->
<style name="MyActionBarTabStyle">
<item name="android:background">#drawable/actionbar_tab_bg</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:gravity">center_horizontal</item>
</style>
<style name="Widget.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:displayOptions">showHome|useLogo|showCustom</item>
<!-- removed as not all activites need it <item name="android:customNavigationLayout">#layout/custom_action_bar</item> -->
<item name="android:background">#drawable/ad_tab_unselected_holo</item>
<item name="background">#drawable/ad_tab_unselected_holo</item>
<item name="android:titleTextStyle">#style/Widget.ActionBar.Title</item>
<item name="titleTextStyle">#style/Widget.ActionBar.Title</item>
</style>
<style name="Widget.ActionBar.Title" parent="Widget">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>
<!-- style the items within the overflow menu -->
<style name="MyDropDownListView" parent="Widget.Sherlock.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/ad_selectable_background</item>
</style>
<!-- style the items within the overflow menu -->
<style name="MySpinner">
<item name="android:background">#drawable/spinner_background</item>
</style>

Wow so it turns out it was as I hadn't stated the parent when themeing ActionDropDownStyle.
It's only when I created a new project was that I discovered it was related to the theme.I presumed it was an issue relating to the code or handling orientation change incorrectly.
Doing the following sorts it:
<!-- style the items within the overflow menu -->
<style name="MySpinner" parent="Widget.Sherlock.Light.Spinner.DropDown.ActionBar" >
<item name="android:background">#drawable/spinner_background</item>
</style>
The only issue now is some of the spinner items are cut off and replaced with ... Although I think this is a known bug.

Related

How to change the height of the contextual action mode on lollipop and above device?

I have implemented the floatingsearchview from here. In my activity i am also having the action mode which is enable on long press on list item.On pre-lollipop the action mode overlays the whole searchview but on post lollipop devices it doesn't as seen in the pictures below
The problem is highlighted in below image.
So i want to increase the height of the action mode how can i do it.Well i already tried with styles attribute in style file.My activity current used style is shown below.
<style name="AppTheme.ContexualActionMode">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorButtonNormal">#color/primary</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">#color/actionModeBachgroundColor</item>
</style>
I also tried this but no solution.
<style name="Widget.ActionModeStyle" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:background">#drawable/action_mode_background</item>
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="android:height">70dp</item><!--or something-->
</style>
with activity style
<style name="AppTheme.ContexualActionMode">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorButtonNormal">#color/primary</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeStyle">#Widget.ActionModeStyle</item>
</style>
can any one help me please.
I guess you found your answer (hopefully) after this long but I was just struggeling with this issue and what worked for me is this:
<style name="AppTheme.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/Blue</item>
<item name="height">104dp</item>
<item name="titleTextStyle">#style/myTitleTextStyle</item>
</style>
and this in your appTheme style
<item name="actionModeStyle">#style/AppTheme.ActionMode</item>
it finally worked for me when i removed the android: prefix from the items

Customizing the 'back' arrow color in Actionmode with appcompat-v7

My main theme is based on Theme.AppCompat.Light as follows:
<style name="core" parent="Theme.AppCompat.Light" >
<!-- Material, Yo!-->
<item name="colorPrimary">#color/theme_main_color</item>
<item name="colorPrimaryDark">#color/deep_purple</item>
<item name="colorAccent">#color/theme_accent_color</item>
<item name="android:navigationBarColor" tools:ignore="NewApi">?attr/colorPrimary</item>
<!-- Toolbar -->
<item name="theme">#style/my_toolbar_theme</item>
<item name="drawerArrowStyle">#style/my_drawer_arrow</item>
<!-- Actionbar -->
<item name="android:actionBarDivider">#null</item>
<item name="android:actionBarTabStyle">#null</item>
<item name="android:actionBarTabBarStyle">#null</item>
<!-- Contextual Actionbar -->
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">?attr/colorAccent</item>
<item name="actionModeStyle">#style/my_actionmode_style</item>
</style>
<style name="my_drawer_arrow" parent="Widget.AppCompat.DrawerArrowToggle" >
<item name="spinBars">true</item>
<item name="color">#color/theme_accent_color</item>
</style>
<style name="my_toolbar_style">
<item name="android:id">#id/toolbar</item>
<item name="android:minHeight">?attr/actionBarSize</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:background">?attr/colorPrimary</item>
<item name="android:elevation" tools:ignore="NewApi">5dp</item>
</style>
<style name="my_actionmode_style" parent="Widget.AppCompat.Light.ActionMode.Inverse" >
<item name="titleTextStyle">#style/my_actionmode_title_style</item>
<item name="subtitleTextStyle">#style/my_actionmode_subtitle_style</item>
</style>
<style name="my_toolbar_style.gradient">
<item name="android:background">#drawable/ab_gradient_bg</item>
</style>
<style name="my_toolbar_theme" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
<!-- Customize the toolbar here -->
</style>
<style name="my_actionmode_title_style" parent="TextAppearance.AppCompat.Widget.ActionMode.Title">
<item name="android:textColor">#color/std_white</item>
</style>
<style name="my_actionmode_subtitle_style" parent="TextAppearance.AppCompat.Widget.ActionMode.Subtitle">
<item name="android:textColor">#android:color/white</item>
</style>
In actionmode I'd like to see white title/subtitles with a white back arrow. I've been able to set the title and subtitle text colors to white, but the back arrow remains black. This issue only occurs in places where I'm using the SupportActionbar and not the toolbar (the back arrow in toolbar is white).
This is my toolbar in ActionMode.
This is the actionbar in ActionMode. Same phone, same app, same themes, just a different activity.
I can't find anything in the themes that would determine this color. According to the source, the icon is #drawable/abc_ic_ab_back_mtrl_am_alpha, which is white, so something must be tinting it. Where does this black-ish color come from?
To customize this using AppCompat:
In your app level theme:
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionModeCloseButtonStyle">#style/myclosebutton</item>
</style>
In the CloseButtonStyle:
<style name="myclosebutton" parent="Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:tint">#ff0</item> <!-- whatever color -->
</style>
I had the same problem and I have solved it by explicitly declaring the icon I want to use in the style:
<item name="android:actionModeCloseDrawable">#drawable/ab_back</item>
Where #drawable/ab_back is provided by me.
This is not ideal, as I would like to correctly set the style and let it work inheriting the right colours from the parent theme, without the need of declaring so specific details. But, I feel everything around the ActionBar, SupportActionBar, SherlockActionBar, ActionBarActivity, FragmentActivityWithASherlockSupportActionToolbar is SO broken and bad engineered that I'm happy to solve it with a workaround.
Try "colorControlNormal" Property Like given Below in your "NoActionBar Theme"
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="colorControlNormal">#android:color/white</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I have best answer for this
Spannable text = new SpannableString( mode.getTitle());
text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorPrimaryDark)),
0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mode.setTitle(text);

Change Color of Actionbar in Android

I am trying to change the background color of actionbar in my App but this is showing different on my app. Instead of coloring the actionbar the whole activity is color.
I am not sure why this is happening? I just want the main actionbar and settings actionbar colored.
Please check the screenshot.
Main Activity Map:
Preference Settings:
I also have transparent Actionbar with UP Navigation enabled for all my sub activities other than the main activity and preference settings activity.
I am not sure why it is showing like the above:
Here is style.xml (values-v14):
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#FF5050</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar.Transparent" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="AppTheme.TransparentActionBar.Light" parent="#style/AppBaseTheme">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar.Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarTabTextStyle">#style/ActionBarTabTextStyle.Tabtheme</item>
<item name="android:actionBarDivider">#drawable/verticallinefordivder</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MapsLocation</item>
</style>
<style name="simpledialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
<style name="ActionBarTabTextStyle.Tabtheme" parent="#style/AppBaseTheme">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ActionBarTabStyle.MapsLocations" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator</item>
</style>
<style name="myPreferenceTheme" parent="#style/AppBaseTheme">
<item name="android:textColor">#color/blue</item>
</style>
<style name="Widget.ActionButton" parent="#style/AppBaseTheme">
<item name="android:background">?android:attr/actionBarItemBackground</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:minWidth">56dip</item>
<item name="android:minHeight">?android:attr/actionBarSize</item>
</style>
</resources>
A little change and you action bar will be red:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#FF5050</item>
</style>
I have changed item in AppBaseTheme & AppTheme.Light.ActionBar .
Now you are good to go. let me know if it works however working at my end :P
You can try set custom view in action bar.
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(you_custom_layout);
I know this is not right answer to this question but if you want to edit your ActionBar, you can use this online Android Action Bar Style Generator.
At least you can create a style and check yours to find differences and learn how to edit your ActionBar.

Android Action Bar not showing on displayOptions - useLogo

I have an actionBarStyle that I have implemented in my app for my ActionBar. Here is the xml code below:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyActionBarTheme" parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/MyCustomActionBar</item>
</style>
<style name="MyCustomActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="android:backgroundSplit">#android:color/transparent</item>
<item name="android:displayOptions">useLogo</item>
</style>
And here is my Activity OnCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setLogo(R.drawable.ic_logo);
setContentView(R.layout.activity_home);
initializeViews();
manageFragments();
}
The Problem is that my ActionBar doesn't show at all and when I remove the displayOptions item from My XML. It shows with the title. Now I can always remove the title (set the title string to just blank) but I don't want that as it shows the default ActionBar style/theme for a few seconds and then my custom theme (I guess you know this one). I don't know what the problem is. Please help. Thanks...
If you set the android:logo in the theme you shouldn't need to set it in code.
I think you may also need showHome in your display options e.g.
<item name="android:displayOptions">showHome|useLogo</item>
EDIT
Below is an example theme I use to hide the logo and display the title in the action bar, this sample is using ActionBarSherlock so you will need to adjust the parent style names accordingly if you aren't using it.
<style name="AppTheme" parent="style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowBackground">#color/background_primary</item>
<item name="android:icon">#drawable/appicon</item>
<!-- For the home as up icon on sub pages -->
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="homeAsUpIndicator">#drawable/back</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showTitle</item>
<item name="displayOptions">showTitle</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="android:background">#color/actionbar_bg_color</item>
<item name="background">#color/actionbar_bg_color</item>
<item name="android:backgroundStacked">#color/actionbar_bg_color</item>
<item name="backgroundStacked">#color/actionbar_bg_color</item>
This works from 4.2 api version.
In your ActionBar style add this…
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
<!-- Support library compatibility -->
<item name="android:logo">#drawable/ic_home</item>
<item name="logo">#drawable/ic_home</item>
Complete Example , adding a new Theme for your complete App.
<!-- This is the generated app theme -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
<!-- Support library compatibility -->
<item name="displayOptions">showHome|useLogo</item>
<item name="android:logo">#drawable/ic_home</item>
<!-- Support library compatibility -->
<item name="logo">#drawable/ic_home</item>
</style>
if you want use code to implement this effect, you can call below code from a Fragment.
ActionBarActivity activity = (ActionBarActivity) getActivity();
activity.getActionBar().setDisplayUseLogoEnabled(true);
activity.getActionBar().setDisplayShowHomeEnabled(true);
and you need to specify the logo attribute of the activity in the AndroidManifest.xml, for example,
<activity
android:name=".....MainEntryActivity"
android:label="#string/label_main"
android:screenOrientation="portrait"
android:logo="#drawable/ic_ios_logo"
android:theme="#style/AppCompatTheme" >
</activity>

ActionBarSherlock spinner item background ignored

I have a share action item, and no matter what I do the spinner does not seem to respect the styles I set. I used the style generator here http://jgilfelt.github.com/android-actionbarstylegenerator/
Here is a snippet of my themes file
<style name="Theme.Next" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_next</item>
<item name="popupMenuStyle">#style/next_PopupMenu</item>
<item name="dropDownListViewStyle">#style/next_DropDownListView</item>
<item name="actionBarTabStyle">#style/next_ActionBarTabStyle</item>
<item name="actionDropDownStyle">#style/next_DropDownNav</item>
<item name="actionBarStyle">#style/next_solid_ActionBar</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_next</item>
<item name="android:popupMenuStyle">#style/next_PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/next_DropDownListView</item>
<item name="android:actionBarTabStyle">#style/next_ActionBarTabStyle</item>
<item name="android:actionDropDownStyle">#style/next_DropDownNav</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.next.widget</item>
<item name="android:actionBarWidgetTheme">#style/Theme.next.widget</item>
</style>
<style name="next_DropDownNav" parent="#style/Widget.Sherlock.Spinner.DropDown.ActionBar">
<item name="background">#drawable/spinner_background_ab_next</item>
<item name="android:background">#drawable/spinner_background_ab_next</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_next</item>
<item name="android:dropDownSelector">#drawable/selectable_background_next</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.next.widget" parent="#style/Theme.Sherlock">
<item name="popupMenuStyle">#style/next_PopupMenu</item>
<item name="dropDownListViewStyle">#style/next_DropDownListView</item>
<item name="android:popupMenuStyle">#style/next_PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/next_DropDownListView</item>
</style>
spinner_background_ab_next points to a selector with my proper custom drawables. No matter what I change, the share spinner always uses the default ICS blue. Anyone run into this problem?

Categories

Resources