Custom theme and sherlockActionBar - android

I am doing a personal theme to use holo widget in 2.3 android.
I did this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppThemes" parent="#style/Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
</resources>
the problem is that widgets don't take the correct style but take the default style. I tried to force assign the #style/EditTextAppTheme at an edittext and it worked.. so the problem is that the theme don't apply.
any idea?
update: the theme apply and work good..the solo problem is some edittext inside a dialog that show with the standard theme

To get the holo theme style in an App for API 10 and below, you can use HoloEverywhere. It's well integrated with ActionBarSherlock. ActionBarSherlock is included as a subproject. https://github.com/ChristopheVersieux/HoloEverywhere

If you want to use a customized Theme you have to set these style attributes in your Application theme. Then apply this theme to the whole App or to a single Activity by defining it in the manifest or setting it programmaticaly in the onCreate() method.
For example(for ABS):
<style name="Theme.myStyle" parent="Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
And then set this theme to your Application or your Activity in the Manifest with:
android:theme="#style/Theme.myStyle"
or programmatically:
setTheme(R.style.Theme.myStyle);

Related

Extracting common attributes from a Dark and Light theme

I have a dark theme and a light theme in my app where the dark theme extends Theme.AppCompat.NoActionBar and the light theme extends Theme.AppCompat.Light.NoActionBar.
I have a lot of custom attributes in those light and dark theme that i have to duplicate in both those themes.
I was wondering if there is a way to actually have all those attributes in a common place and be used by both light and dark theme.
Example below to make things even more clear:
<style name="MotherThemeDark" parent="Theme.AppCompat.NoActionBar">
<!-- Base application theme common to all sdk versions -->
<!--Colors-->
<item name="colorPrimaryDark">#color/brand_dark</item>
<item name="colorPrimary">#color/brand</item>
<item name="colorAccent">#color/brand_accent</item>
<item name="colorPositive">#color/positive</item>
<item name="colorPositiveDark">#color/positive_dark</item>
<item name="colorNegative">#color/negative</item>
<item name="colorNegativeDark">#color/negative_dark</item>
<item name="colorNegativeLight">#color/negative_light</item>
<item name="colorMedium">#color/medium</item>
....
...Things specific to this theme goes here
....
</style>
<style name="MotherTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Base application theme common to all sdk versions -->
<!--Colors-->
<item name="colorPrimaryDark">#color/brand_dark</item>
<item name="colorPrimary">#color/brand</item>
<item name="colorAccent">#color/brand_accent</item>
<item name="colorPositive">#color/positive</item>
<item name="colorPositiveDark">#color/positive_dark</item>
<item name="colorNegative">#color/negative</item>
<item name="colorNegativeDark">#color/negative_dark</item>
<item name="colorNegativeLight">#color/negative_light</item>
<item name="colorMedium">#color/medium</item>
....
...Things specific to this theme goes here
....
</style>
One of the ways is to put the common attributes in a theme overlay (assuming you are using the AppCompat library), e.g. -
<style name=“MyCustomOverlay” parent=”ThemeOverlay.AppCompat”>
<item name="colorPrimaryDark">#color/brand_dark</item>
<item name="colorPrimary">#color/brand</item>
<item name="colorAccent">#color/brand_accent</item>
<item name="colorPositive">#color/positive</item>
<item name="colorPositiveDark">#color/positive_dark</item>
<item name="colorNegative">#color/negative</item>
<item name="colorNegativeDark">#color/negative_dark</item>
<item name="colorNegativeLight">#color/negative_light</item>
<item name="colorMedium">#color/medium</item>
</style>
and then apply android:theme=”MyCustomOverlay” to your root views. This will override the attributes set in your base theme (e.g. MotherTheme or MotherThemeDark) for the root views and all child views. Works for API 11+.
Reference: https://plus.google.com/+AndroidDevelopers/posts/JXHKyhsWHAH
Although I made the above post as an answer, since it helped me find a solution i will post the actual solution here :
I made the dark theme extend ThemeOverlay.AppCompat.Dark and then applied the motherThemeDark to the root layout of the fragment/activity that i wanted to be themed dark. Under the motherThemeDark i only had attributes that i wanted to override for a dark theme.
<style name="MotherTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Base application theme common to all sdk versions -->
<!--Colors-->
<item name="colorPrimaryDark">#color/brand_dark</item>
<item name="colorPrimary">#color/brand</item>
<item name="colorAccent">#color/brand_accent</item>
<item name="colorPositive">#color/positive</item>
<item name="colorPositiveDark">#color/positive_dark</item>
<item name="colorNegative">#color/negative</item>
<item name="colorNegativeDark">#color/negative_dark</item>
<item name="colorNegativeLight">#color/negative_light</item>
<item name="colorMedium">#color/medium</item>
....
...Things specific to this theme goes here
....
</style>
<style name="MotherThemeDark" parent="ThemeOverlay.AppCompat.Dark">
....
....
...Things specific to this theme goes here
....
</style>

The different between <item name="title"> and <item name="android:title">

I make ActionBar in app.I change ActionBar style.There are some questions.
I want to change the title in the ActionBar.
So I write the follow code.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="actionOverflowButtonStyle">#style/overflowButton</item>
</style>
<!--ActionBar-->
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bg</item>
<item name="background">#color/bg</item>
<item name="android:title">#string/test</item>
<item name="title">#string/test</item>
</style>
<style name="overflowButton">
<item name="android:src">#mipmap/ic_add_black_48dp</item>
<item name="android:showAsAction"></item>
</style>
</resources>
when I only write <item name="android:title">#string/test</item> ,it doesn't work,but write <item name="title">#string/test</item> it work.
I have try to solve in Android Developer,but fail.Please help me.
<item name="title">#string/test</item>
this tag works on supporting library, and
<item name="android:title">#string/test</item>
this one works on your android. For more detail please have a look on here
I hope you understand, If not please let me know.
Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher). In doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties included in the Support Library (the appcompat.R.attr properties—the context for these properties is actually your app).

Styling my app with custom colors

I'm trying to apply some styles to my app. I've created a custom theme for the ActionBar using this actionbarstylegenerator.
But I want to change also in my app, the stock blue Holo color, to a red one, at least on buttons.
So, I have the custom theme for the ActionBar (Compat), and for the other side, a custom theme to change the Holo color.
In my app, I have defined the custom theme for the Actionbar, and I want to set the custom Holo theme inside the Actionbar's theme, but I don't know how to call, or where can I find the item name's whose define the variable you want to modify.
This is, I need to set this:
<style name="ColorTheme" parent="android:Theme.Black">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>
</style>
Inside of this:
<style name="Theme.CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="actionBarItemBackground">#drawable/ab_selectable_background</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionDropDownStyle">#style/DropDownNav</item>
<item name="actionBarStyle">#style/ActionBar.Transparent</item>
<item name="actionModeBackground">#drawable/cab_background_top_customactionbartheme</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_customactionbartheme</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode</item>
</style>
Maybe you need to do this?
<style name="ColorTheme" parent="Theme.CustomActionBarTheme">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>

Android custom theme

Hello I'm making a custom theme for my app. I want to have a custom ActionBar and background for the rest of the app (below the ActionBar). I'm wondering how to do the background. Right now I have:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/dActionBar</item>
</style>
<style name="dActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#4C721D</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Would I just have to do <item name-"android:background"></item> in MyTheme or would I have to create another style? After I create this do I need to put it in the res/styles folder? Also what are the API restrictions on this, if any?
Don't forget to apply your theme to your application in your AndroidManifest.xml.
<application android:theme="#style/CustomActivityTheme" ... />
You can find all the information about styling the Actionbar here.
To style your ActionBar with a nice Holo-look, try this website
Hope this helps!
Try to use below code in your Style.xml file
<resources>
<style name="Theme.Sample" parent="Theme.AppCompat">
<item name="android:colorBackground">#color/primary_material_dark</item>
<item name="actionBarTheme">#color/colorGray</item>
</style>
</resources>
Just need to use android:colorBackground as a name of item to define the background color like as below:
<item name="android:colorBackground">#color/primary_material_dark</item>
Hope you get your answer,Thanks.

Custom style is interfering with platform dialogs

I've created a custom theme for my app, and it looks great! However, I've noticed that some default platform dialogs, such as the context menu when long-pressing an EditText doesn't show correctly.
On the left, a context menu through my app. On the right, a standard context menu through a platform app.
Here's my style.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="Theme.Sherlock">
<!-- ... various app styles ... -->
<item name="android:alertDialogStyle">#style/DialogHolo</item>
<item name="android:dialogTheme">#style/DialogHolo</item>
</style>
<style name="DialogHolo" parent="android:style/Theme.Dialog">
<item name="android:fullDark">#drawable/bg_dialog_full</item>
<item name="android:topDark">#drawable/bg_dialog_top</item>
<item name="android:centerDark">#drawable/bg_dialog_middle</item>
<item name="android:bottomDark">#drawable/bg_dialog_bottom</item>
<item name="android:fullBright">#drawable/bg_dialog_full</item>
<item name="android:centerBright">#drawable/bg_dialog_middle</item>
<item name="android:bottomBright">#drawable/bg_dialog_bottom</item>
<item name="android:bottomMedium">#drawable/bg_dialog_bottom</item>
<item name="android:centerMedium">#drawable/bg_dialog_middle</item>
<item name="android:textColor">#ffe6e7e8</item>
</style>
</resources>
Is it possible to either have these dialogs use the default style or get the text to appear in the desired text color?
I never found an elegant solution for this, and instead simply provided a theme defined separately in my style.xml when displaying a custom dialog.

Categories

Resources