ActionBasSherlock, Holoeverywhere and themes - android

I'm trying to implement the choice of two themes, Dark and Light.
The dark one is working fine, but when I choose the light theme it's rendered not correctly (the action bar is light, the text is dark but the backgorund is still dark).
By the way in the eclipse preview it's shown correctly.
I'm using the dev branch from Holoeverywhere and I'm extending the themes like this:
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="DarkTheme" parent="Holo.Theme"/>
<style name="LightTheme" parent="Holo.Theme.Light"/>
</resources>
Any help?
EDIT
I've just tried with the emulator (3.2, on a tablet) and it's showing the theme correctly.
I will do a couple of tests and eventually open an issue on github.

I've finally found the solution: Theme_HoloEverywhereLight_Sherlock showing dark background
(I've looked for hours and it came up just now.)
Basically the setTheme should be done before everything, even before the super.onCreate(savedInstanceState);, I was doing it just after..

Related

How can I stop dark mode from messing up how my app looks?

I am a student trying to learn app development with android studio. For my first project, im just building a basic calculator app. I have stumbled across a problem that I couldnt solve and didnt find a helpfull post about. It occurs when I trun on dark mode on the virtual device. Here are 2 pictures showing what happens.
How it looks with dark mode
How it is supposed to look
My activity_main.xml consists of some buttons that all have the same style and a TextView.
I left all the other files untouched. Id love some advice on how to fix this. Thanks for reading!
You are most likely using the following default DayNight theme in your themes.xml file (values/themes/themes.xml)
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
If you don't want things to change in night mode, you can change that to use the Light theme instead
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
and delete the themes.xml (night) file if it exists. There is some extra info about these options here
there are two themes : night and not night check in IDE Design tab you can view how it looks in both click the circle in pane where design is displaying it displays Not Night and Night whatever theme you are using it will affect because of these two modes, by default IDE shows not night
To show screen same in both modes you need to change some settings like in your activity_main.xml at root layout change background to #color/white and see what happens it should be sorted out since your button colors are dark ...the text Placeholder color needs to be changed accordingly
<LinearLayout
background=#color/white
other layout etc to follow

Change background and text color of overflow items

I want to change the background and text colors of the pop up menu that appears when the user presses the overflow icon.
If I use Theme.Holo or Theme.Holo.Light it works, but I'm using Theme.Holo.Light.DarkActionBar and it never works. I'm starting to assume that it's an Android bug.
I'm testing on a Nexus 4 with 4.4.2 but it also doesn't work on an emulator with API 19.
After trying a lot of potential solutions that I came across here in StackOverflow, here is what I'm doing:
<style name="Theme.MyApp" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/ActionBarWidget</item>
</style>
<style name="AndroidPitActionBarWidget" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#android:style/Widget.Holo.Light.PopupMenu</item>
<item name="android:dropDownListViewStyle">#android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>
That works but it changes the styling of the SearchView, which is another pain to change.
So I'm not considering this a solution.
What I want is to just change the background/text of the popup to the Light version, which is light background with black text.
I also tried setting those two attributes in the main theme instead of using the actionBarWidgetTheme.
It's really frustrating to waste hours on this kind of problems.
I also tried using Action Bar Style Generator to make the background white, but then the text is white and I can't change it to black.
Thanks very much in advance.
If you set the background color of that panel using the theme you get in the Action Bar Style Generator, you can try adding the android:textColor attribute of the drop down ListView.
If that does not work, you can alternately set the string color in code during your onCreateOptionsMenu method as detailed on this SO thread

Weird behaviour with drawables color in Android 4.0 or above

I have a strange problem with android resources. I have app created on Android 2.2 (android:minSdkVersion="8"). The application works fine.
When I installed app on for example Android 4.0, the application works fine, however at first run some resources are changed.
For example, I have drawable color named primary_color which refers to #FFFFFF html color. After installation, the system renders black color instead of white. In some cases #android:color/white renders black color.
Force closing app and restart app solving this problem.
Please help me to solve this issue.
This is caused by a bug in Android versions 4.0 to 4.1.3, I have been testing a similar problem with drawables turning to black only on devices with these versions, it is not present in devices with android version > 4.2.
I'm sure you noticed in your own research but it does not seem to be documented properly and there is no official solution but I can provide a few workarounds:
1) Turn off hardware acceleration, I used a different solution for my problem but this has been known to resolve some issues with images in the above mentioned Android versions. If you want hardware acceleration on for your application you can disable it for the problem activity by adding this to the activity declaration in your manifest.
<activity
android:name="activityName"
android:hardwareAccelerated="false"/>
2) For a solution specific to your example try setting the color to #android:color/transparent, this resolved my issue where I needed a background drawable to remain white.
3) Refer here: http://code.google.com/p/android/issues/detail?id=34619 to see a similar, documented bug and some of those solutions may work for your issue as well.
HTH
I came across the exact same problem!
I had this on colors.xml
<resources>
<color name="white">#ffffffff</color>
</resources>
And on styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/white</item>
</style>
The problem was that when using fragment(which contains a ListView) inside an activity the ListView shows white color as background(which is what I need) at first run but at second run the ListView background was black. The problem only existed on Android 4.0(I did not test on 4.1) but worked fine on Android 4.3, 4.4, 5 etc.
Turns out only white color had the problem, when colors other than white was used there was no black background issue!
So as I wanted a white background and I did not want to have overdraw of having multiple background so setting white as the windowBackground on styles.xml was important but at the same time it causes black background issues!
So as solution, I created another color which is not completely white but its white
<resources>
<color name="fakewhite">#fffefefe</color>
</resources>
And on styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/fakewhite</item>
</style>
Hence, in short color #ffffffff gets converted to #00000000 for Views like ListView and I also notice this behaviour on ScrollView.
This may not be a perfect solution but it worked for me!

Style ActionMode

I am using ActionBarSherlock and trying to style ActionMode. I can change background and done button using these attributes in my style:
<item name="android:actionModeCloseDrawable">#drawable/abs__ic_cab_done_holo_dark</item>
<item name="android:actionModeBackground">#drawable/actionbar_bg</item>
But I can not figure out how to set the color of the vertical line just next to the done button. Does anyone know how to do this?
I solved it with this code in my theme:
<item name="android:actionModeCloseButtonStyle">#style/action_button_done</item>
And the style action_button_done just sets the background drawable:
<style name="action_button_done" parent="Widget.Sherlock.ActionButton.CloseMode">
<item name="android:background">#drawable/abs__btn_cab_done_holo_dark</item>
</style>
Warning
This should be a simple thing to do. And it was, but for some reason htc decided to put an extra layer on top of the button that makes it impossible to style it. I was just lucky that I tried deploying on my friends samsung galaxy nexus and noticed that it actually worked. I only used htc one x, so don't know if it is the same on other htc devices.

Android - Make a custom titlebar that uses the device's current titlebar theme

I'm trying to make a custom titlebar for my first Android application.
While I can find lots on the web about how to make them so you can change colours etc, I want my titlebar to look the same as the "standard" titlebar, but with a button that I can configure. This means copying the device's currently active themes to be able to style it in exactly the same way.
Not all devices simply use a gradient in the titlebar style, so adding a gradient (as suggested in other SO questions) doesn't really make sense.
Does anyone have any pointers how to read the style information?
try to extend an existing theme e.g.
create your own style which can ofcourse extend from existing from an existing theme. change the windowNoTitle to true.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="noTitleBarStyle" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/darkGrey</item>
<item name="android:colorForeground">#ff3333</item>
</style></resources>
or try to do it runtime as discussed here
Android - change custom title view at run time
I hope this helps.

Categories

Resources