All popups became white - android

After updating old android project to be able to build project with Android Studio 3.2.1, all popups became white.
All AlertDialog, ProgressDialog, Spinner got white background and white text.
If i change theme in the app, some text become readable but whiteness persist.
I solved some of them by hacks like this:
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY));
but this doesn't work everywhere.
What can be the cause?
This is first time i work with android in seven year, i was doing iOS before, so this is new territory for me.
Update:
Comments helped to pinpoint that issue was regarding themes.
Now, challenge was digging out what was causing white backgrounds.
I had to set parent to my custom attribute:
parent="Base.Theme.AppCompat"
So in my custom theme there was this attribute: android:alertDialogTheme
<style name="CustomMobileTheme.Base.Black" parent="Base.Theme.AppCompat">
<item name="android:alertDialogTheme">#style/Theme.AppCompat.Dialog.Alert</item>
<item name="android:colorPrimary">#color/actionBarColorBlackTheme</item>
<item name="android:statusBarColor">#000000</item>
That was making all this mess. I have no idea what android:alertDialogTheme does, it is not specified in Spinner documentation and i had to manually comment out about 200 attributes in the theme, to dig out this culprit and spend about 13 hours of my private time. I wish to the developer who made this suffer some bad karma.

All AlertDialog, ProgressDialog, Spinner got white background and white text.
It may Becuase of "colorAccent" in your application theme is white.
Please check your theme for "colorAccent". If not specified then please specify with color which you want. check below code.
<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>

Related

Activity Layout goes blank when switched to Material Design components

Problem :
There was no problem when app was using
Theme.MaterialComponents.Light.NoActionBar
But was not using any MDC elements in Layout like (TextInputLayout etc).
Then i replaced Editext with TextInputLayout and Button with Material Button.
Now here the problem comes.
When i run my app, i see the screen goes blank. Just pure white.
I checked Layout isses.
I found there're 7 warnings and 2 errors(Render problem).
The Render problems are as -
Path.op() not supported. (As was it suggests i refreshed the layout many times. Doesn't work)
java.awt.geom.IllegalPathStateException: missing initial move to in path definition
This is what i have tried -
Downgrading my MDC dependency (how to solve render problem Path.op() not supported?)
Clean project, rebuild and restart Android studio
Please help me to solve this strange issue.
I want to use MDC in my project.
Thank you.
I would suggest you should first make use of the Bridge then, gradually override the parent theme attributes based on your requirement design.
In AndroidManifest.xml
android:theme="#style/MyMaterialTheme"
Then under style.xml. it would like something like
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:windowBackground">#color/white</item>
<item name="toolbarStyle">#style/BlueToolbar</item>
</style>
try referring reference , reference
Simple solution is make your theme extend a Bridge theme :) I hope this helps

Change holo spinner text colour

I have a spinner in a Holo theme dialog and am trying to change the text colour because it is very hard to read:
I have looked at android styles.xml, as well as many other answers, and believe that I am setting the custom style correctly; but it's just not getting picked up.
This is an extract from the dialog layout file where the spinner lives:
<Spinner
android:id="#+id/spn_Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/dose_type_options"
style="#style/DialogSpinner" />
And these are the relevant entries in styles.xml in the values-v14 folder:
<style name="DialogSpinner" parent="#android:style/Widget.Holo.Spinner">
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MySpinnerItem" parent="android:Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearanceSpinnerItem</item>
</style>
<style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
</style>
The dialog itself is forced to the Holo dark theme by using:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
</style>
Can anyone identify why the spinner text isn't white?
I have looked at other solutions, which suggest changing the colour in code, but this app supports 2.3.* upwards, so for those non-holo versions black text is fine, hence trying to do it by styles.
Thanks
Updated using answer from Woda below
The text colour of the initial value of the spinner is now white, which goes a long way to highlighting that there is a spinner there for the user:
But the text colour of the selectable items is still black. I guess it's not a massive deal, at least the existence of the spinner has been affirmed by getting the initial text changed to white. But I would be interested to know why the items are still black, and how to change them to white.
Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:
theme.xml:
<style name="exampleTheme" parent="android:Theme.Holo.Light">
<item name="android:spinnerItemStyle">#style/SpinnerItem_example</item>
...
</style>
style.xml:
<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#000000</item>
</style>
Update:
Taking a deeper look into the styles.xml brought me this:
<style name="Widget.DropDownItem.Spinner">
<item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>
<style name="Widget.DropDownItem">
<item name="android:textAppearance">#style/TextAppearance.Widget.DropDownItem</item>
<item name="android:paddingStart">#dimen/dropdownitem_text_padding_left</item>
<item name="android:paddingEnd">#dimen/dropdownitem_text_padding_right</item>
<item name="android:gravity">center_vertical</item>
</style>
So you probably need to customize the Widget.DropDownItem and accept it in your theme.
...
<item name="dropDownItemStyle">#android:style/Widget.DropDownItem</item>
...
For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.
themes.xml
styles.xml
I fixed it by calling
mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());
Hope this helps someone ;)
You can access the internal TextView in code without changing any styles. This is how I handled enabling and disabling Spinners
The .getSelectedView() did not work for me. So I tricked the Spinner to "show" being disabled.
You will need to define your own colors for the "disabled" look.
For Example:
R.color.blue_text //means enabled
R.color.gray_text //means disabled
So to disable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
mySpinner.setEnabled(false);
mySpinner.setFocusable(false);
To enable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
mySpinner.setEnabled(true);
mySpinner.setFocusable(true);
The getChildAt(0) function allows you to access the first item in the spinner, which is what you show on the screen as a TextView.
You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.

Light.DarkActionBar menu item text colour unchangeable?

The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black.
My main theme contains
<item name="android:panelBackground">#drawable/menu_hardkey_panel</item>
...Where #drawable/menu_hardkey_panel is a dark coloured 9patch.
The resulting appearance of the menu popup is...
I'm unable to determine why this is happening, or how to manually change the colour of the text. In my main theme, I've tried all of the following...
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">#style/MyMenuTextAppearance.Large</item>
<item name="android:textAppearanceSmallPopupMenu">#style/MyMenuTextAppearance.Small</item>
I've even tried
<item name="android:actionBarWidgetTheme">#style/Theme.MyApp.Dark</item>
...Where Theme.MyApp.Dark is...
<style name="Theme.MyApp.Dark" parent="#style/Theme.Sherlock">
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
</style>
None have let me change the text to white. If I make my base theme inherit from Theme.Sherlock, the problem is solved and the text is white, but unfortunately that's not an option.
Not entirely sure about this, but I believe the pop-up menu uses the same styling as the overflow menu. In which case you'd just do something like this.
<item name="android:itemTextAppearance">#style/your_new_text_appearance</item>
<style name="your_new_text_appearance">
<item name="android:textColor">#android:color/white</item>
</style>
Giving it a chance: there is a text appearance called actionMenuTextAppearance. Have you tried that?
Update: I did some more digging and I believe that this file is the layout And there they refer to textAppearanceListItemSmall and textAppearanceSmall. However, it takes this value from a special theme which is specified as following in Theme.Holo.Light
<item name="panelMenuListTheme">#android:style/Theme.Holo.Light.CompactMenu</item>
And like this in Theme.Holo:
<item name="panelMenuListTheme">#android:style/Theme.Holo.CompactMenu</item>
The problems comes from the fact that the parent of Sherlock.__Theme.DarkActionBar is Theme.Sherlock.Light. This is not valid for the dark action bar. Taking the line from Theme.Holo should do the trick.
In my research I haven't found a way to change the text color, but you can at least handle hardkey menus gracefully.
This link provided me with a passable solution to the problem:
https://github.com/jgilfelt/android-actionbarstylegenerator/issues/30
Commenting out the "android:panelBackground" item from my generated theme allowed the text to at least be visible on hardkey menus, even if it doesn't perfectly match the theme.
You could also try replacing the "menu_hardkey_panel_whatever.9.png" drawable with something that will work for your theme and the black text.
For me this solves the problem, try this instead:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<item name="actionBarWidgetTheme">#null</item>
<item name="android:actionBarWidgetTheme">#null</item>
...
</style>
I found the solution, use:
getSupportActionBarContext()
e.g.
ArrayAdapter<CharSequence> list =
ArrayAdapter.createFromResource(getSupportActionBarContext(), R.array.navigation, layout.simple_spinner_item);
list.setDropDownViewResource(layout.simple_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
I think that due to the fact that Theme.Sherlock.Light.DarkActionBar don't style its contents right is due to the actionWidgetTheme attribute is used with a ContextThemeWrapper for inflating the action bar views (Jake Wharton's own words), thus something like the following (not tested) will be needed to fulfill your needs, though breaking your need of not using Theme.Sherlock as parent in one way:
<style name="MyColorTheme" parent="Theme.Sherlock">
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="YourMainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/MyColorTheme</item>
<item name="actionMenuTextAppearance">#style/MyColorTheme</item>
</style>
Might work or not work. That's the question :)

Android - gray background instead of white

Each "layout" I set a white background and "Manifest" I set Theme.Light.
Still receives a gray background instead of white. Why?
Edit:
Manifest.xml
android:theme="#android:style/Theme.Light.NoTitleBar">
Layout
android:background="#android:color/white"
Theme.Light does not mean that it will be white. It just means that it will be light, not dark :P This is not theme.white.
Each device manufacturer can customize Android OS on his phone for example to preferred colors and look & feel. In particular he can define styles for his Android implementation - Light and dark. Thanks to that your app may look differently on various devices, however it will always fit the style used on this device (every app in style Theme.Light will have grey background on this device, unless you set android:background="#android:color/white" )
Your device's manufacturer defined style Theme.Light as style with grey background.
Hope that I am clear - otherwise do not hesitate to ask
I had the same issue until I changed #android:color/white to explicit android:background="#FFFFFF". Weird though...
Since it's an old question this might have another solution already but anyway one can just enter the AppTheme style tag in styles.xml, you can do so by pressing the ⌘cmd key and clicking on your theme declaration in the manifest.
Over there add this line with your preferred color -
<item name="android:windowBackground">#color/white</item>
This line basically overrides the theme's default background value.
Example -
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorControlActivated">#color/black</item>
<item name="android:windowBackground">#color/white</item>
</style>

How to change background color of child preference screen in honeycomb

I have been searching for the solution for the last several days but could not find one.
I need to change the background color of the right pane (I know how to change the color of the left parent preference). I created a new theme in manifest file.
<activity android:name=".PreferenceWithHeaders"
android:label="#string/app_name"
android:theme="#style/PreferencesTheme">
</activity>
Below is the PreferencesTheme portion of styles.xml
<style name="PreferencesTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">#drawable/background</item>
</style>
I am, however, unable to change the default gray background color of the child PreferenceScreenwhich is on the right. Please take a look at the picture.
I tried different things but they don't have any impact on the background color. Any pointers will be deeply appreciated!
I had this same issue not long ago; couldn't figure it out at the time, even after trying many of the solutions here. Finally stumbled upon a fix after running into a similar issue.
I just finished writing a blog post about it that explains in more detail, Fixing empty white space issues with Android ListViews, but basically you should be able to get rid of the white space by setting overScrollFooter to #null.
As overScrollFooter is only available in Android 2.3.3+ (API Level 10+), you'd have something like this:
res/values/styles.xml
<style name="MyListView" parent="#android:style/Widget.ListView">
</style>
res/values-v10/styles.xml
<style name="MyListView" parent="#android:style/Widget.ListView">
<item name="android:overScrollFooter">#null</item>
</style>
And of course update your PreferencesTheme to use it:
<style name="PreferencesTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:listViewStyle">#style/MyListView</item>
</style>

Categories

Resources