I have a big problem. I cant set background for ToolBar when I start ActionMode.
I got this:
I try much variants, but I didn't find answer for me (
This is my style:
<style name="DriverNotesAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/material_bg</item>
<item name="colorPrimaryDark">#color/status_bar</item>
<item name="colorAccent">#color/edittext_primary</item>
<item name="android:windowBackground">#color/light_blue</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColorPrimaryInverse">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:actionModeBackground">#color/material_light_bg</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="drawerArrowStyle">#style/WhiteDrawerIconStyle</item>
<item name="textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
<item name="android:actionModeStyle">#style/LStyled.ActionMode</item>
<item name="popupMenuStyle">#style/ThemeOverlay.AppCompat.Light</item>
<item name="android:popupMenuStyle">#style/myPopupMenuStyle</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
<item name="android:textColor">#000000</item>
</style>
<style name="LStyled.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/material_light_bg</item>
</style>
try this one,
toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
Theme / Style
<style name="MyToolbarStyle">
<item name="android:maxHeight">#dimen/abc_action_bar_default_height_material</item>
<item name="android:background">#color/primary</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="titleTextAppearance">#style/Theme.Toolbar.Title</item>
<!-- No need for colorPrimary, colorPrimaryDark, colorAccent here
this should go to the AppTheme -->
</style>
for more detail visit this
Related
im using Material IO and i want to Change the Text-Color of my Menu.
<resources>
...
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="android:textColorPrimary">#color/colorText</item>
</style>
...
<resources>
Does exactly that. But it changes every Text Color. But i just want to Change the Color of my Menu-Text.
So i tried to change only that:
<style name="ActionBarTheme" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:textColor">#color/colorMenuText</item> //android.view
<item name="android:textColorPrimary">#color/colorMenuText</item>
<item name="android:actionMenuTextAppearance">#color/colorWhite</item>
<item name="android:background">#color/colorAccent</item>
<item name="popupTheme">#style/ActionBarPopupTheme</item>
<!-- backward compatibility -->
<item name="background">#color/colorAccent</item>
</style>
by writing some Thing like This.
I can change the Menu-Background this way, but i cant change the Menu-Text-Color this way. I tried everything i found on Stackoverflow but i couldnt fix this issue.
Whole Styles.xml
<resources>
<style name="ActionBarTheme" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:textColor">#color/colorMenuText</item> //android.view
<item name="android:textColorPrimary">#color/colorMenuText</item>
<item name="android:actionMenuTextAppearance">#color/colorWhite</item>
<item name="android:background">#color/colorAccent</item>
<item name="popupTheme">#style/ActionBarPopupTheme</item>
<!-- backward compatibility -->
<item name="background">#color/colorAccent</item>
</style>
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorAccent">#0000FF</item>
</style>
<style name="ActionBarPopupTheme">
<item name="android:textColor">#color/colorMenuText</item>
<item name="android:background">#color/colorMenuBackground</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- MENU -->
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
<item name="actionBarStyle">#style/ActionBarTheme</item>
<!-- DIALOG -->
<item name="md_color_title">#color/colorPrimary</item>
<item name="md_color_content">#color/colorPrimaryDark</item>
<item name="md_color_button_text">#color/colorAccent</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorTest2</item>
<item name="colorPrimaryDark">#color/colorTest3</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:actionMenuTextColor">#color/colorMenuText</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="color">#color/colorTest4</item>
<item name="colorSecondary">#FF0000</item>
<item name="android:colorBackground">#color/colorBackground</item>
<item name="colorError">#color/colorError</item>
<item name="colorPrimaryVariant">#color/colorAccent</item>
<item name="colorSecondaryVariant">#color/colorTest</item>
<item name="colorSurface">#313131</item>
<item name="colorOnPrimary">#00BCD4</item>
<item name="colorOnSecondary">#00BCD4</item>
<item name="colorOnBackground">#673AB7</item>
<item name="colorOnError">#2196F3</item>
<item name="colorOnSurface">#color/colorOnAccent</item> <!-- placeholder farbe -->
<item name="scrimBackground">#E607FF</item>
<item name="android:editTextColor">#color/colorText</item>
<item name="android:textColorPrimary">#color/colorText</item>
<item name="android:textColorSecondary">#color/colorText</item>
<item name="android:textColorTertiary">#color/colorText</item>
<item name="android:textColorPrimaryInverse">#color/colorText</item>
<item name="android:textColorSecondaryInverse">#color/colorText</item>
<item name="android:textColorTertiaryInverse">#color/colorText</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorMenuText</item>
</style>
<style name="Theme.MyApp" parent="Theme.AppCompat">
<!-- DIALOG -->
<item name="md_color_title">#color/colorPrimary</item>
<item name="md_color_content">#color/colorPrimaryDark</item>
<item name="md_color_button_text">#color/colorAccent</item>
<!-- Original AppCompat attributes. -->
<item name="colorPrimary">#color/colorTest4</item>
<item name="colorSecondary">#color/colorTest5</item>
<item name="android:colorBackground">#color/colorBackground</item>
<item name="colorError">#color/colorError</item>
<!-- New MaterialComponents attributes. -->
<item name="colorPrimaryVariant">#color/colorAccent</item>
<item name="colorSecondaryVariant">#color/colorTest</item>
<item name="colorSurface">#313131</item>
<item name="colorOnPrimary">#9C27B0</item>
<item name="colorOnSecondary">#00BCD4</item>
<item name="colorOnBackground">#673AB7</item>
<item name="colorOnError">#2196F3</item>
<item name="colorOnSurface">#E91E63</item>
<item name="scrimBackground">#FFC107</item>
<item name="textAppearanceHeadline1">#style/TextAppearance.MaterialComponents.Headline1</item>
<item name="textAppearanceHeadline2">#style/TextAppearance.MaterialComponents.Headline2</item>
<item name="textAppearanceHeadline3">#style/TextAppearance.MaterialComponents.Headline3</item>
<item name="textAppearanceHeadline4">#style/TextAppearance.MaterialComponents.Headline4</item>
<item name="textAppearanceHeadline5">#style/TextAppearance.MaterialComponents.Headline5</item>
<item name="textAppearanceHeadline6">#style/TextAppearance.MaterialComponents.Headline6</item>
<item name="textAppearanceSubtitle1">#style/TextAppearance.MaterialComponents.Subtitle1</item>
<item name="textAppearanceSubtitle2">#style/TextAppearance.MaterialComponents.Subtitle2</item>
<item name="textAppearanceBody1">#style/TextAppearance.MaterialComponents.Body1</item>
<item name="textAppearanceBody2">#style/TextAppearance.MaterialComponents.Body2</item>
<item name="textAppearanceCaption">#style/TextAppearance.MaterialComponents.Caption</item>
<item name="textAppearanceButton">#style/TextAppearance.MaterialComponents.Button</item>
<item name="textAppearanceOverline">#style/TextAppearance.MaterialComponents.Overline</item>
</style>
</resources>
I tried this minimum sample of your code and it gives me the desired behavior
I think there is a conflict with your styles
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="actionBarTheme">#style/ActionBarTheme</item>
</style>
<style name="ActionBarTheme" parent="#style/ThemeOverlay.MaterialComponents.ActionBar">
<item name="android:textColorPrimary">#ffffff</item>//for title text color
<item name="colorPrimary">#D81B60</item>// for toolbar background
<item name="popupTheme">#style/ActionBarPopupTheme</item>
</style>
<style name="ActionBarPopupTheme">
<item name="android:textColor">#304FFE</item> // for option menu text color
</style>
I'm using a transparent ActionBar with a white title. Unfortunately the title has its own background.
This is my styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorPrimary">#color/app_color</item>
<item name="android:colorPrimaryDark">#ff077fb1</item>
<item name="android:colorAccent">#color/app_color</item>
<item name="android:windowActionModeOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="colorPrimary">#color/app_color</item>
<item name="colorPrimaryDark">#ff077fb1</item>
<item name="colorAccent">#color/app_color</item>
<item name="windowActionModeOverlay">true</item>
</style>
<style name="MyActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="background">#drawable/actionbar_background</item>
</style>
Here is the toolbar used:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
sothree:theme="#style/MyActionBar">
How can I get rid of that blue title background?
I'm doing this when defining textAppearance in toolbar
sothree:titleTextAppearance="#style/MyToolbar.TextAppearance"
style
<style name="MyToolbar.TextAppearance">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/toolbar_title_text_color</item>
<item name="android:background">#color/mytransparentcolor</item>
</style>
I solved this by removing
<item name="android:background">#drawable/actionbar_background</item>
<item name="background">#drawable/actionbar_background</item>
from styles.xml and adding the background color programatically to the toolbar using
toolbar.setBackgroundColor(myColor);
I have a navigation bar at the top of my app. It look fine if galaxy/htc devices as follows:
However, in nexus devices it seems to shift a little as follows, not sure why:
Here is my code for the same : (actionbar.xml) :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:foo="http://schemas.android.com/apk/res/com.justin.abc"
android:id="#+id/title_information_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#27272b"
android:fillViewport="true" >
<com.justin.abc.utils.FontTextView
android:id="#+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="#dimen/actionbar_title_height"
android:layout_marginTop="#dimen/actionbar_title_topmargin"
android:layout_marginLeft="#dimen/common_left_padding"
android:text="#string/title_about"
foo:customFont="proxima-nova-regular-Regular.ttf"
android:textColor="#color/white"
android:textSize="#dimen/actionbar_title" />
<Button
android:id="#+id/button_done"
android:layout_width="wrap_content"
android:layout_height="#dimen/done_button_height"
android:layout_marginTop="#dimen/done_button_topmargin"
android:layout_alignParentRight="true"
android:layout_marginLeft="#dimen/done_button_leftmargin"
android:layout_marginRight="#dimen/done_button_rightmargin"
android:background="#drawable/done_cancel_button"
android:text="#string/menu_done"
android:textColor="#drawable/done_button_text"
android:textSize="#dimen/button_text" />
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_marginTop="#dimen/actionbar_view_margintop"
android:background="#color/black"
android:visibility="visible" />
</RelativeLayout>
Any clues how I can fix the same so it works well in all devices? Thanks!
This is the associated theme:
<style name="AppTheme" parent="#style/Theme.Sherlock"></style>
<style name="AppTheme.NoActionBar" parent="#style/Theme.Sherlock.NoActionBar"></style>
<style name="AppBaseTheme.NoActionBar" parent="AppTheme.NoActionBar"></style>
<!-- Although this is doing exactly what AppBaseTheme is doing,
it fixes the initialization display of the icon being truncated -->
<style name="ABTheme" parent="AppTheme">
<item name="homeAsUpIndicator">#null</item>
<item name="selectableItemBackground">#drawable/btn_selector_home_icon</item>
</style>
<style name="AppBaseTheme" parent="AppTheme">
<item name="homeAsUpIndicator">#null</item>
<item name="selectableItemBackground">#drawable/btn_selector_home_icon</item>
<item name="android:listViewStyle">#style/ListViewAppTheme</item>
<item name="android:listViewWhiteStyle">#style/ListViewAppTheme.White</item>
<item name="android:spinnerItemStyle">#style/SpinnerItemAppTheme</item>
</style>
<style name="ListViewAppTheme" parent="android:Widget.ListView">
<item name="android:listSelector">#drawable/list_selector_holo_light</item>
</style>
<style name="ListViewAppTheme.White" parent="android:Widget.ListView.White">
<item name="android:listSelector">#drawable/list_selector_holo_light</item>
</style>
<style name="SpinnerItemAppTheme" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#000000</item>
</style>
<style name="abc.TextView" parent="android:Widget.Holo.TextView"></style>
<style name="T1UserContactCountry">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#cccccc</item>
<item name="android:textSize">#dimen/title</item>
<item name="android:paddingLeft">#dimen/common_left_padding</item>
<item name="android:layout_gravity">left</item>
</style>
<style name="T1UserContactPhone">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/abs__holo_blue_light</item>
<item name="android:textSize">#dimen/title</item>
<item name="android:onClick">onPhoneNumberClicked</item>
<item name="android:paddingRight">#dimen/common_right_padding</item>
<item name="android:layout_gravity">right</item>
<item name="android:clickable">true</item>
</style>
<style name="T1TableRowSeparator">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
</style>
<style name="T1ViewSeparator">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">2dp</item>
<item name="android:background">#color/header_grey</item>
<item name="android:layout_span">2</item>
</style>
<style name="abc.TextView.ListsTextView">
<item name="android:ellipsize">end</item>
<item name="android:gravity">right</item>
<item name="android:singleLine">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
<style name="abc.TextView.ListsTextView.Header">
<item name="android:paddingTop">2dp</item>
<item name="android:textSize">15sp</item>
<item name="android:background">#android:color/transparent</item>
</style>
<style name="CustomTheme">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
<style name="abc.TextView.ListsTextView.Value">
<item name="android:textSize">15sp</item>
<item name="android:background">#android:color/transparent</item>
</style>
<style name="abc.TextView.NavigationItem">
<item name="android:clickable">true</item>
<item name="android:padding">3dp</item>
<item name="android:textSize">20sp</item>
<item name="android:background">#color/black</item>
</style>
<style name="search_autosuggest_header" parent="android:Widget.Holo.TextView">
<item name="android:paddingBottom">5dp</item>
<item name="android:paddingLeft">3dp</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/search_autosuggest_header_text</item>
<item name="android:background">#drawable/background_search_auto_suggest_header</item>
<item name="android:textStyle">bold</item>
</style>
<style name="abc.TextView.Preferences">
<item name="android:padding">8dp</item>
</style>
<style name="abc.TextView.Preferences.Title">
<item name="android:background">#color/black</item>
<item name="android:textColor">#color/background_preferences_item</item>
</style>
<style name="abc.TextView.Preferences.Item">
<item name="android:background">#color/background_preferences_item</item>
<item name="android:textColor">#color/background_preferences_title</item>
</style>
<style name="abc.TextView.Preferences.Item.clickable">
<item name="android:background">#drawable/background_preferences_layout_selector</item>
<item name="android:textColor">#color/background_preferences_title</item>
</style>
<style name="abc.Button.Toggle" parent="android:Widget.Holo.Button.Toggle">
<item name="android:button">#null</item>
<item name="android:textOff"></item>
<item name="android:textOn"></item>
<item name="android:background">#drawable/toggle_selector_abc</item>
</style>
<style name="LoginEditText" parent="#android:style/Widget.EditText">
<item name="#android:textColor">#color/textbox_hint</item>
<item name="#android:textSize">16sp</item>
<item name="#android:maxLines">1</item>
<item name="#android:fontFamily">Roboto-Regular</item>
</style>
<style name="MenuDialogAnimation">
<item name="android:windowEnterAnimation">#anim/grow_from_topright_to_bottomleft</item>
<item name="android:windowExitAnimation">#anim/shrink_from_bottomleft_to_topright</item>
</style>
<style name="MenuDialogAnimationLeft">
<item name="android:windowEnterAnimation">#anim/grow_from_topleft_to_bottomright</item>
<item name="android:windowExitAnimation">#anim/shrink_from_bottomright_to_topleft</item>
</style>
<style name="BriefcaseMenuDialogAnimation">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
<style name="ButtonText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">30dp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
<item name="android:paddingLeft">15dp</item>
<item name="android:paddingRight">15dp</item>
</style>
<style name="Divider">
<item name="android:divider">#drawable/divider</item>
<item name="android:dividerHeight">1px</item>
</style>
<style name="related_buttons" parent="android:Widget.Holo.TextView">
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|left</item>
<item name="android:layout_marginBottom">3dp</item>
<item name="android:layout_marginTop">3dp</item>
<item name="android:paddingLeft">12dp</item>
<item name="android:paddingRight">12dp</item>
<item name="android:visibility">gone</item>
<item name="android:drawableRight">#drawable/arrow_chevron_selector</item>
</style>
In my manifest I am referencing it as follows:
<application
android:name=".abcApplication"
android:allowBackup="true"
android:icon="#drawable/abc_launcher"
android:label="#string/app_long_name"
android:theme="#style/ABTheme" android:debuggable="false">
Here's my java code:
public void manageActionBar() {
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar_no_button);
getSupportActionBar().setDisplayShowHomeEnabled(false);
final TextView titleView = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title);
titleView.setText(R.string.personal);
}
The reason this is not working is because this is not the way you customize the Action Bar, I suggest reading about how to customize the Action Bar here.
What you want to do basically is define a theme for your application, as you stated in the comments you want to change the look based on your project requirements.
Here is the example from the article I've linked above:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:backgroundStacked">#drawable/actionbar_background</item>
<item name="android:backgroundSplit">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/actionbar_background</item>
<item name="backgroundSplit">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
After doing that, you can customize the look of your Action Bar to look just the way you want it to (Make sure you set the colors the right way).
I'm having some problem with the ActionBar as well. And the problems only appears on Nexus 7 (I don't have other Nexus). I placed my custom view inside the action bar, to completely cover it up (because it can't be configure to the way I want).
LayoutParams layout = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT );
LayoutInflater inflator = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View v = inflator.inflate( R.layout.my_actionbar_layout, null );
getActionBar().setDisplayShowCustomEnabled( true );
getActionBar().setDisplayShowHomeEnabled( false );
getActionBar().setCustomView( v, layout );
However, there is a gap on the left size and the view goes too far over the right edge of screen.
The solution, however, is very simple:
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Hope this help you (and others).
Credits:
I found the answer from this page:
http://answer.techwikihow.com/1352928/actionbar-customview-extra-padding-cannot-removed.html
This question already has answers here:
How to change the text color of action bar sherlock
(3 answers)
Closed 9 years ago.
I have tried multiple different ways to change the tab text color to actionbarshelock to white and it simply does not work. Here is my styles.xml file.
<style name="Theme.Test" parent="#style/Theme.Sherlock.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_test</item>
<item name="popupMenuStyle">#style/PopupMenu.Test</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Test</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Test</item>
<item name="actionDropDownStyle">#style/DropDownNav.Test</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Test</item>
<item name="actionModeBackground">#drawable/cab_background_top_test</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_test</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Test</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_test</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Test</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Test</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Test</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Test</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Test</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_test</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_test</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Test</item>
</style>
<style name="ActionBar.Solid.Test" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_test</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_test</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_test</item>
<item name="progressBarStyle">#style/ProgressBar.Test</item>
<item name="android:background">#drawable/ab_solid_test</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_test</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_test</item>
<item name="android:progressBarStyle">#style/ProgressBar.Test</item>
<item name="android:titleTextStyle">#style/Test.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/Test.ActionBar.TitleTextStyle</item>
<item name="actionBarTabTextStyle">#style/MyTabTextStyle</item>
<item name="android:actionBarTabTextStyle">#style/MyTabTextStyle</item>
<item name="android:actionBarStyle">#style/YOURTHEME.ActionBarStyle</item>
<item name="actionBarStyle">#style/YOURTHEME.ActionBarStyle</item>
</style>
<style name="YOURTHEME.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:titleTextStyle">#style/YOURTHEME.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/YOURTHEME.ActionBar.TitleTextStyle</item>
</style>
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="MyTabTextStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabText">
<item name="android:textColor">#color/white</item>
<item name="android:background">#color/white</item>
</style>
<style name="Test.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="ActionBar.Transparent.Test" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="background">#drawable/ab_transparent_test</item>
<item name="progressBarStyle">#style/ProgressBar.Test</item>
<item name="android:background">#drawable/ab_transparent_test</item>
<item name="android:progressBarStyle">#style/ProgressBar.Test</item>
</style>
<style name="PopupMenu.Test" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_test</item>
</style>
<style name="DropDownListView.Test" parent="#style/Widget.Sherlock.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_test</item>
</style>
<style name="ActionBarTabStyle.Test" parent="#style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_test</item>
</style>
<style name="DropDownNav.Test" parent="#style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_test</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_test</item>
<item name="android:dropDownSelector">#drawable/selectable_background_test</item>
</style>
<style name="ProgressBar.Test" parent="#style/Widget.Sherlock.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_test</item>
</style>
<style name="ActionButton.CloseMode.Test" parent="#style/Widget.Sherlock.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_test</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Test.Widget" parent="#style/Theme.Sherlock">
<item name="popupMenuStyle">#style/PopupMenu.Test</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Test</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Test</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Test</item>
</style>
I want to make my text color white but I have no idea how to accomplish this. I'd appreciate if anyone can help me with this.
Thanks!
I got it to work.
This should be in the theme
<item name="actionBarTabTextStyle">#style/tabtextcolor</item>
<item name="android:actionBarTabTextStyle">#style/tabtextcolor</item>
This should be where you define the tab text color.
<style name="tabtextcolor" parent="#style/Widget.Sherlock.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
</style>
I'm using ActionBarSherlock and HoloEverywhere in my app. I used the ActionBar Style Generator to generate my styles and then modified them a bit by hand for text colors, etc.
I'm having a problem where my ActionBar looks correct on my Android 4.2 device (that is, orange with white text), but on my Android 2.3 device the ActionBar is black with grey text.
Does anyone know what might cause this?
<style name="Theme.MyApp" parent="#style/Holo.Theme.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_MyApp</item>
<item name="android:popupMenuStyle">#style/PopupMenu.MyApp</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.MyApp</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MyApp</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.MyApp</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.MyApp</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_MyApp</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_MyApp</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.MyApp</item>
<!-- <item name="android:textColorPrimary">#FFFFFF</item> -->
<item name="android:spinnerDropDownItemStyle">#style/ActionBar.Solid.MyApp.NavigationDropDownStyle</item>
</style>
<style name="ActionBar.Solid.MyApp" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_solid_MyApp</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_MyApp</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_MyApp</item>
<item name="android:progressBarStyle">#style/ProgressBar.MyApp</item>
<item name="android:titleTextStyle">#style/ActionBar.Solid.MyApp.TitleTextStyle</item>
</style>
<style name="ActionBar.Solid.MyApp.NavigationDropDownStyle" parent="#android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textAppearance">#style/ActionBar.Solid.MyApp.NavigationDropDownStyle.TextStyle</item>
</style>
<style name="ActionBar.Solid.MyApp.NavigationDropDownStyle.TextStyle" parent="#android:style/Widget">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">18sp</item>
</style>
<style name="ActionBar.Solid.MyApp.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">18sp</item>
<!-- <item name="android:fontFamily">sans-serif-medium</item> -->
</style>
<style name="ActionBar.Transparent.MyApp" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_MyApp</item>
<item name="android:progressBarStyle">#style/ProgressBar.MyApp</item>
</style>
<style name="PopupMenu.MyApp" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_MyApp</item>
</style>
<style name="DropDownListView.MyApp" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_MyApp</item>
</style>
<style name="ActionBarTabStyle.MyApp" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_MyApp</item>
</style>
<style name="DropDownNav.MyApp" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_MyApp</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_MyApp</item>
<item name="android:dropDownSelector">#drawable/selectable_background_MyApp</item>
</style>
<style name="ProgressBar.MyApp" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_MyApp</item>
</style>
<style name="ActionButton.CloseMode.MyApp" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_MyApp</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.MyApp.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.MyApp</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.MyApp</item>
</style>
--------------- EDIT ----------------------
So I'm now having a problem where the action bar is taking up the entire screen on the Android 2.3 device (but works fine on Android 4.2). Do I need to remove the "android:" from the parent attributes?
parent="#android:style/Widget.Holo.ListPopupWindow"
When I tried this, Eclipse was unable to find the theme.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.MyApp" parent="#style/Holo.Theme.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_MyApp</item>
<item name="android:popupMenuStyle">#style/PopupMenu.MyApp</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.MyApp</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MyApp</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.MyApp</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.MyApp</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_MyApp</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_MyApp</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.MyApp</item>
<!-- <item name="android:textColorPrimary">#FFFFFF</item> -->
<item name="android:spinnerDropDownItemStyle">#style/ActionBar.Solid.MyApp.NavigationDropDownStyle</item>
<item name="actionBarItemBackground">#drawable/selectable_background_MyApp</item>
<item name="popupMenuStyle">#style/PopupMenu.MyApp</item>
<item name="dropDownListViewStyle">#style/DropDownListView.MyApp</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.MyApp</item>
<item name="actionDropDownStyle">#style/DropDownNav.MyApp</item>
<item name="actionBarStyle">#style/ActionBar.Solid.MyApp</item>
<item name="actionModeBackground">#drawable/cab_background_top_MyApp</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_MyApp</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.MyApp</item>
<!-- <item name="textColorPrimary">#FFFFFF</item> -->
<item name="spinnerDropDownItemStyle">#style/ActionBar.Solid.MyApp.NavigationDropDownStyle</item>
</style>
<style name="ActionBar.Solid.MyApp" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_solid_MyApp</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_MyApp</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_MyApp</item>
<item name="android:progressBarStyle">#style/ProgressBar.MyApp</item>
<item name="android:titleTextStyle">#style/ActionBar.Solid.MyApp.TitleTextStyle</item>
<item name="background">#drawable/ab_solid_MyApp</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_MyApp</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_MyApp</item>
<item name="progressBarStyle">#style/ProgressBar.MyApp</item>
<item name="titleTextStyle">#style/ActionBar.Solid.MyApp.TitleTextStyle</item>
</style>
<style name="ActionBar.Solid.MyApp.NavigationDropDownStyle" parent="#android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textAppearance">#style/ActionBar.Solid.MyApp.NavigationDropDownStyle.TextStyle</item>
</style>
<style name="ActionBar.Solid.MyApp.NavigationDropDownStyle.TextStyle" parent="#android:style/Widget">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">18sp</item>
</style>
<style name="ActionBar.Solid.MyApp.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">18sp</item>
<!-- <item name="android:fontFamily">sans-serif-medium</item> -->
</style>
<style name="ActionBar.Transparent.MyApp" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_MyApp</item>
<item name="android:progressBarStyle">#style/ProgressBar.MyApp</item>
<item name="background">#drawable/ab_transparent_MyApp</item>
<item name="progressBarStyle">#style/ProgressBar.MyApp</item>
</style>
<style name="PopupMenu.MyApp" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_MyApp</item>
</style>
<style name="DropDownListView.MyApp" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_MyApp</item>
</style>
<style name="ActionBarTabStyle.MyApp" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_MyApp</item>
<item name="background">#drawable/tab_indicator_ab_MyApp</item>
</style>
<style name="DropDownNav.MyApp" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_MyApp</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_MyApp</item>
<item name="android:dropDownSelector">#drawable/selectable_background_MyApp</item>
<item name="background">#drawable/spinner_background_ab_MyApp</item>
</style>
<style name="ProgressBar.MyApp" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_MyApp</item>
</style>
<style name="ActionButton.CloseMode.MyApp" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_MyApp</item>
<item name="background">#drawable/btn_cab_done_MyApp</item>
</style>
</resources>
As per the official docs, you need to also declare the attributes without the android: namespace. In your case, those attributes are only getting applied to the native implementation.