Android spinnerStyle not working - java

First excuse me for my english.
Im designing a theme (With HoloEveryWhere) and im trying to style default spinner.
The problem is that the spinnerStyle is not working. I'm testing with this layout.
<Spinner
android:id="#+id/spCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/etPhone" />
And im using this for my theme.xml..
<item name="android:spinnerStyle">#style/Coloquium.Spinner.Ruby</item>
and in styles.xml
<style name="Coloquium.Spinner.Ruby" parent="#style/Holo.Spinner.Light">
<item name="android:background">#drawable/spinner_holo_white</item>
</style>
The problem is that the spinner style is never applied (Others styles like edittextstyle or buttonstyle works fine), the background never change, But i tried this style as spinnerItemStyle and work fine, but spinnerItemStyle is the inner view, and i want to style the outer, the spinner.
If i set background directly in the layout node, the background change fine, but i need to set spinnerStyle for all spinners in the theme, not in layout.
I test a lot of post looking for a solution without success.

The solution is:
HoloEveryWhere appear use "spinnerStyle" and not "android:spinnerStyle".
But really... I can't find the HoloEveryWhere documentation about this. :S

Related

Change PreferenceFragmentCompat dialog background color in Android

I recently started working with PreferenceFragmentCompat and MaterialComponents and noticed that in Dark mode, Dialogs generated by preferences like ListPreference always have that weird grey android background no matter how many background attributes I change in the style.
(source: pocketnow.com)
This I've tried:
<item name="android:windowBackground">#color/colorPrimaryDark</item>
<item name="android:colorBackground">#color/colorPrimaryDark</item>
<item name="android:colorBackgroundFloating">#color/colorPrimaryDark</item>
I've also tried with android:background and worked but it brokes everything.
So I investigated a bit in-depth at elements like EditTextPreferenceDialogFragment and most of them create and show an AlertDialog instance in the same function of PreferenceDialogFragment without any possibility to change its style.
Or at least that's the conclusion I've come to after some research on the subject.
My question is, has anyone found a workaround for this? Am I doing something wrong? Cause I would like to have those dialogs matching my app theme even if it's just the background color.
Btw, sorry if it has been already answered before. I also searched in here but found nothing and similar answers for different problems without results. Thanks.
Found it! After reading more the AndroidX package found that by default the AlertDialog.Builder retrieves a default theme from an attribute when no specified in the constructor. You can see it here
So a solution would be to add a specific theme for dialogs in the activity like this:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="alertDialogTheme">#style/AlertDialogCustom</item>
</style>
And then you setup your dialog theme like:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FFC107</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#4CAF50</item>
</style>
And this is the result:
Bonus tip: If you want to also setup the default theme for
MaterialAlertDialogBuilder you must change de attribute
materialAlertDialogTheme

How to transform XML layouts uniformly across Android apps?

I am looking into code injection for Android apps (written in Java). Let's say I have a set of ImageViews declared similarly as such within separate layout files in .../layout/ :
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#color/colorPrimary"
tools:layout_editor_absoluteX="70dp"
tools:layout_editor_absoluteY="38dp" />
Now let's say I have the following attribute:
android:rotation="180"
My goal is to add this attribute to every single ImageView in every .xml file in the layout directory on run-time, so that I do not have to edit the source code of these .xml files. How would I go about doing this?
You can do this dynamically. What you need to do is to find the image view on activity and call set rotation method and give angle as you are giving in xml file.
And second way of doing the same thing is you can provide customize style for image view in styles folder of the project.And this will be very simple and far more effective way of doing so. To achieve this via style, you can use below code.
<style name="TitleBarImage">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:src">#drawable/lock</item>
<item name="android:rotation">180</item>
</style>
and in every image view, you need to use this below code to get the reflection of style
<ImageView style="#style/TitleBarImage" />
Hope this will help you.

Toast inheriting theme background

I'm having an issue with developing on Android that I have tested on multiple devices and am having the same issues on all devices.
I'm creating a style named SplashTheme, in which I am setting android:background to a green color which matches my app identity. The issue I am having is whenever I create a Toast in this activity, the Toast is partially green. I have tried removing the styling to android:background and it resolves the issue, however, I am needing to style the background in that way.
Any ideas as to why this could be happening?
Instead of:
<item name="android:background">#color/your_color</item>
Do:
<item name="android:windowBackground">#color/your_color</item>

Android DatePicker Selector Color

So, this question is kind of an extension of this question, I solved the issue with the headerBackground but I realised that I had manually set the theme of my DatePicker in my layout using android:theme="#style/State0DatePickerTheme. But when I removed that line from my XML, the day selector just turned back to white (my accent colour defined in my base theme). Any thoughts on why this is, or how to fix it?
For my purposes, I need to have the theme for DatePicker set in my styles.xml with android:datePickerStyle because I'm setting my theme dynamically in my onCreate() and I can't change the theme of the datePicker in java (at least not that I'm aware of).
So, I figured out how to fix it, I simply created a new theme (which I called State0HistoryTheme) and then made its parent State0BaseTheme and applied that theme to my entire activity in my onCreate() using setTheme()
This is what my State0HistoryTheme looks like for those curious:
<style name="State0HistoryTheme" parent="State0BaseTheme">
<item name="colorAccent">#color/state0Dark</item>
</style>
This was able to override the colorAccent that I had set in State0BaseTheme

Android using 9-patch works for some buttons but not others?

In my main activity, I was able to use my 9-patch images for the backgrounds of the 4 main buttons by coding into the XML.
main activity xml
<button
style="#style/button_default"/>
^ This works, and the buttons on the main activity use the button_default.xml images for the button states.
Then, I try to do the exact same thing in another activity using the exact same method, and it doesn't work. The buttons are still the default gray. I then tried using the java method to set the background
java file for different activity
//This works
buttonOne.setBackgroundColor(Color.RED);
//This does NOT work
buttonOne.setBackgroundResource(R.drawable.button_default);
So, whether I try setting the background for the buttons through XML or Java, I can't get it to work. But, I can get it to work only in the main activity. Is this common, or is there a reason why it isn't working?
#alanv, here's the very simple style/button_default that's located in styles.xml
<style name="button_default">
<item name="android:background">#drawable/button_default</item>
</style>

Categories