ActionBarSherlock with Action Bar Style Generator - android

for the last few days I'm trying to implement custom theme, which is created by Action Bar Style Generator to my application. I'm able to use theme with some generic samples from SDK, but I'm not able to use it with my application which uses ActionBarSherlock.
My application with ActionBarSherlock is a modified sample of Tabs and Pager.
Steps which I do:
Create theme with Android Action Bar Style Generator.
Copy theme to res folder inside my application.
Change theme in Manifest file.
After those steps only 'Action bar color' changes to correct one. All other styles are not used in application. I have tried many different approaches which I found online, but without success.
Thank you very much for your help.

Did you add the proper items to your App's theme in styles.xml? You need to use attributes that are NOT prefixed with android:, for example:
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="background">#drawable/bg_striped</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
You would also keep the properly prefixed ones for Android versions that have native actionbar.
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:background">#drawable/bg_striped</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
The best place to understand this is to look at the demo provided with the ActionBarSherlock library project.

I managed to fix the problem.
I missed android:background attribute in TabWidget. This partially
solves the problem.
I had to set setLeftStripDrawable and setRightStripDrawable programatically.

Related

How can I call the style of a new Library as parent in style.xml?

I am building a new library for Android and a demo project that I am using to test the library.
The library that I made has a style called Light and in the demo I am applying this style in Java using setTheme(R.style.Light) but I would like to replace it calling the theme directly in style.xml. What I have right now in the demo/res/values/style.xml is
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
and I would like to replace it with something similar to:
<style name="AppTheme" parent="myLibrary.Light">
I have tried with parent="#style/Light" but it's not working.
Does anyone know how I can do it?
To inherit styles from a library or your own project, declare the parent style name without the #android:style/ part. For example, the following example inherits text appearance styles from the support library:
<style name="GreenText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#00FF00</item>
</style>
For more details
I found the solution,
My problem was that in my library I had different styles depending on the version of Android. For each version of Android my main theme was referred to different parents by mistake. I just changed the parents in my library making sure that they are referring to the same one and it fixed my problem. Now in my app I can refer to the theme created in my library without crashing the application.

Android define custom style for Menu item

I want to customize text style Android menu item.
I put this to styles.xml
<item name="android:actionMenuTextAppearance">#style/my_custome_actionbar_menu_item</item>
It does not work, but when I remove "android:", it work properly
<item name="actionMenuTextAppearance">#style/my_custome_actionbar_menu_item </item>
Do you know What is different between having "android: " and not?
if you use api7-13,use actionMenuTextAppearance,and if your sdk api>17,use android:actionMenuTextAppearance,maybe the sdk you are using is lower than 17.
I figure out the reason about AppCompat
With new AppCompat-v7 (v21) ActionBar style's properties need to refer to the app namespace, that is without android: prefix.
So,for retro-compatibility, we should use actionBarStyle along with android:actionBarStyle:

Customizing Support Action Bar / Android

I recently started Android programming, all is good and dandy, but I've came across a problem that I couldn't find an answer to, and I really diged hard for 4 days so far.
My app uses support action bar, and to be specific "android.support.v7.app.ActionBarActivity". Long story short, I couldn't handle most of the stuff applicable to an Action Bar to this support one.
My app uses this support action bar by default due to setting up my mini sdk version to 14.
I want to be able to build an action bar from scratch, and customize it, since the default action bar is not responsive to my customization in styles.xml, etc.
I don't mind using Holo theme library instead of AppCompat.
So the question here, how can use Action Bar instead of Support Action Bar?
How can I extend my java class to use that instead of the support one?
Because none of the online customizing solutions are applicable to the support action bar.
A bit foggy description so I apologize for that.
Create a new project, and select the minimum API level as 15. When you do this, the appcompat-v7 library will not be required for this project as it is for projects with minSdkversion < 15. In this project, the classes android.app.ActionBarActivity and android.app.ActionBar will be used by default, i.e. the native AOSP classes and not the ones from the support library.
The following will let you have an ActionBar with custom background color as you want it, on API level 8 and above.
STEP 1. In your res/values folder, define an XML file theme.xml and add the following to it:
<resources
xmlns:tools="http://schemas.android.com/tools">
<style name="DefaultActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:targetApi="11">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarSize" tools:targetApi="11">#dimen/action_bar_wrap_content</item>
<item name="actionBarSize">#dimen/action_bar_wrap_content</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background" tools:targetApi="11">#color/actionbarbgcolor</item>
<item name="background">#color/actionbarbgcolor</item>
<item name="android:height" tools:targetApi="11">#dimen/action_bar_wrap_content</item>
<item name="height">#dimen/action_bar_wrap_content</item>
</style>
</resources>
In the same folder make another XML file colors.xml and add the following to it:
<resources>
<color
name="actionbarbgcolor">#00FF00
</color>
</resources>
and to the existing file dimens.xml, add the last line:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- Optional, in case you wish to increase the default width of the Action Bar. -->
<dimen name="action_bar_wrap_content">55dp</dimen>
</resources>
In place of #00FF00 above, use the hex color code for the background color you wish to use in your ActionBar.
NOTE: The above will work assuming you are using the appcompat-v7 library. If not, then you'll have to use one of the Holo.Light themes instead of AppCompat.Light, and there will be other changes as well.
STEP 2. In your manifest file, you must add:
android:theme="#style/DefaultActionBarTheme"
to every <activity declaration if that Activity has the ActionBar.
Try this. It will work.
Zygotelnit answer works but you have to omit the ["tools:targetApi="11"] from item declaration otherwise it will give you an error for some reason.
On the other hand, I've found a much shorter and easier but not so optimized solution.While searching through the actionBar class and playing around here is the answer:
In your activity.java, go down to
protected void onCreate(Bundle savedInstanceState)
Anywhere appropriate in that method, write the following code:
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#D62D20")));
You replace the color code by any color code of your choosing. It's obviously a hex color code.

What are the themes/styles used for theming the overflow dropdown menu

I am trying to theme the overflow dropdown menu but I am having trouble finding the correct themes and styles for this part of the actionbar.
I am currently looking in the following files:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
Could anyone enlighten me please?
I managed to find what I wanted by creating a bogus holo theme here:
http://jgilfelt.github.com/android-actionbarstylegenerator/
Then I just looked at the example inside the zip file and updated my themes/styles files as so:
<item name="android:popupMenuStyle">#style/MyApp.Theme.PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/MyApp.Theme.DropDownListView</item>
<style name="MyApp.Theme.PopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/theme_menu_popup_background</item>
</style>
<style name="MyApp.Theme.DropDownListView" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/theme_menu_popup_selector</item>
</style>
I would like to know how to totally overhaul everything but it seems I can only ever manage to drip feed my app with those essential theme/style specific bits because it takes soooo long to find the necessary styling syntax. If only there was an easier way.
Of course I have no idea how to position the ListPopupWindow or even change the color of the text but it's good enough for now.

How do I style the title text in ActionBarSherlock 4.0?

Hello i use ActionBarSherlock Version 4.0.0 and i dont know how to change/style the title text, under version 3.5 i used #style/abTextStyle.
but that doenst work in version 4.0.0.
ABS 4 brought with it some major improvements, one being the styling via XML. If you read the documentation on styling, you would know that as of 4.0 -
Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation. Since
both theming APIs are exactly the same you need only reference your
customizations twice rather than having to implement them twice.
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
From this we can see that the ABS item reflects the native exactly, obviously without the android prefix.
This in short means that styling the native and ABS actionbar is now much simpler and to do any styling you should follow the standard Android docs on this, and then declare the styling you want like the example above (i.e. declare twice, once for native once for ABS).
This question ActionBar text color has some examples for what you want in its top voted answer, and if you want to be comforted: it was commented on by Jake Wharton who is the genius behind ABS.

Categories

Resources