In theory a simple thing. I would like to change the background color of toast (android:minSdkVersion="14" android:targetSdkVersion="18"). What I did? I've found the Theme.Holo.Light definition which I use as parent for my own style:
Theme.Holo.Light definition
Next I've found:
<item name="android:toastFrameBackground">
Nest I wanted to modify it:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:toastFrameBackground">#android:color/holo_blue_light</item>
etc.
While for Action Bar it works without problems, for toastFrameBackground eclipse displays always:
error: Error: No resource found that matches the given name: attr 'android:toastFrameBackground'. styles.xml Android AAPT Problem
I've even set it to the original version (just copied from original theme definition):
<item name="toastFrameBackground">#android:drawable/toast_frame</item>
Hoping it should work. No way.
When I click ctr+space Eclipse it seems not to see toastFrameBackground. Why? I've checked some other items from original theme definition and some seems to be visible, while others no.
Any idea? help?
I've spent 3-4 hours and nothing... Probably I will keep the original toast background color as it seems it's not worth to fight but I would prefer to understand deeper the mechanism. Why I don't have an access to the item it seems I should have an access.
That's because toastFrameBackground is not exported and did not make to public.xml, which means this attribute is not available for non-platform/third-party applications.
However, you may want to see https://stackoverflow.com/a/9903465/1893766 for what you are trying to achieve.
Related
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
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>
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
i'm just getting started with developing Android Apps. Therefore i have a question, for designing my GUI. Maybe there is a possible build-in widget, but i don't have the right wording to find it (English is not my native language).
I'm looking for something like the Rating Bar, where you can select a value between 1 and 5. Instead of the stars, i'd like to have some bars (the left one is the smallest, the right one the highest). Should look like the "Stairs" within a Signal strength notification. To make it a bit more challenging i'd like to have different colors for every bar (least value is green, highest value red). Therefore i don't think that the Rating Bar with different drawings will fit my needs, because afaik i could just change the star layout, not like the first star should become a 5dp bar, the second a 15dp and so on.
Is there any build in widget i could use?
I attached a picture to show my idea.
I hope you can help me
what you want is easily achievable with a level-list. In your case you need five different drawables, on for each level and then combine them in a drawable xml file, like:
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/no_level"
android:maxLevel="0" />
<item
android:drawable="#drawable/first_level"
android:maxLevel="1" />
<item
android:drawable="#drawable/second_level"
android:maxLevel="2" />
<item
android:drawable="#drawable/third_level"
android:maxLevel="3" />
<item
android:drawable="#drawable/forth_level"
android:maxLevel="4" />
</level-list>
and set this drawable as source for an ImageView, for instance. At runtime, retrieve the ImageView and call setImageLevel, with a value from 0 and 4, and the corresponding level will be displayed
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