in this simple designed Theme, Android could not find numberPickerStyle ino that and i get this error:
Failed to find 'numberPickerStyle' style in current theme
My theme is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tsms" parent="#style/Theme.AppCompat.Light">
<item name="numberPickerStyle">#style/SampleTheme.Tsms</item>
</style>
<style name="SampleTheme.Tsms" parent="#style/Theme.AppCompat">
<item name="numberPickerStyle">#style/NPWidget.Holo.Light.NumberPicker</item>
</style>
</resources>
how to fix and resolve this problem?
I am assuming you copied your code from this StackOverflow answer. numberPickerStyle would be an attribute that is defined in your app. The code that you copied from the answer does not work. You would need to define an attribute in XML for the error to go away but that still would do nothing for you.
You can't style a NumberPicker. android:numberPickerStyle is private (see this issue).
Unfortunately, you can't style it. The styles and styling attributes
for NumberPicker are not present in the public API, therefore you
can't set them and change the default look. You can only select
between light and dark theme. source
Related
I know I might be making more than enough mistakes here. But do lemme know.
I've tried going through MaterialIO documentation the best way I can, and it all looks so spun up and complicated with a dozen links in each page redirecting me to another minor component.
That's when I decided to TRY it.
I added materialIO stuff to my dependencies
I then added Material to my manifest file, and wrote this
<application ...
android:theme="#style/Theme.MaterialComponents.DayNight" >
</application>
Next, I made a values/themes.xml and values-night/themes.xml as instructed by some part of the material IO page.
My intuition was to write a style tag in those resources that extended the Material theme and set my color values. The colors I found from the materialIO page :
Background (0dp elevation surface overlay)-->
Surface (with 1dp elevation surface overlay)-->
Primary
Secondary
On background
On Surface
On Primary
On Secondary
So I started adding the tags to values-night/themes.xml. I couldn't apply android: to some tags and some tags raised errors when I did.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppCompat.." parent="Theme.MaterialComponents.DayNight">
<item name="android:colorBackground">#color/JDBG</item>
<item name="colorSurface">#color/JDSurface</item>
<item name="colorPrimary">#color/JDPrimary</item>
<item name="android:colorSecondary">#color/JDSecondary</item>
<item name="android:OnBackground">#color/JDOnBackground</item>
<item name="android:OnSurface">#color/JDOnSurface</item>
<item name="OnPrimary">#color/JDOnPrimary</item>
<item name="OnSecondary">#color/JDOnSecondary</item>
</style>
</resources>
Then I added the colors to the respective colors.xml and colors-night.xml files, which told me that those values didn't have a declaration in the base values folder and it might raise issues.
I do not want to toil at nothing with very abstract documentation that leads me on ten directions at every point. Hence the question . . .
Is there anything wrong I've done ?
What do I do next ?
Just define your theme in a resources file.
For example res/values/styles.xml:
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#color/....</item>
<item name="colorSecondary">#color/....</item>
<item name="colorOnPrimary">#color/....</item>
<item name="colorOnSecondary">#color/....</item>
.....
</style>
Define the colors in res/values/colors.xml and res/values-night/colors.xml.
Then apply the theme in the Manifest:
<application ...
android:theme="#style/MyTheme" >
Check also the official guide.
Could somebody please tell me what the difference is between
?android:attr/colorPrimary
and
?attr/colorPrimary
Whichever i use, result is the same. Altough first option causes android.view.InflateException on some devices.
Both almost works the same often. when you use ?attr/colorPrimary, its works totally fine as compiler already knows that 'android' has to be appended.
And regarding you saying that ?android:attr/colorPrimary gives you exception then in that case, try using the second option only ..
For Example in your styles.xml : The following may/may not work everytime
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">#color/primary_material_dark</item>
<item name="android:colorPrimaryDark">#color/primary_dark_material_dark</item>
</style>
</resources>
But this majorly works :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary_material_dark</item>
<item name="colorPrimaryDark">#color/primary_dark_material_dark</item>
</style>
The builder knows that the color comes from attr so it's redundant. The documentation states:
... you do not need to explicitly state the type ... you can exclude the attr type.
See: App resources overview: Referencing style attributes
As for android: - the prefix in android:colorPrimary refers to an attribute of the material theme (API 21 and later). Without the prefix, ?colorPrimary will be taken from the support library.
This has been posted before but I still cannot figure it out. I want to change the text color of my actionbar, preferrably programmatically (is that even possible?).
I looked at examples at:
https://developer.android.com/training/basics/actionbar/styling.html
but I get "or: Error retrieving parent for item: No resource found that matches the given name '#style/Theme.Holo'."
I am using For Android 3.0 and higher only:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
...
Isn't there a simpler way to do it? I mean you can get the actionbar but there seems to be no method .setTextColor, why not?
Instead of
parent="#style/Theme.Holo"
use
parent="#android:style/Theme.Holo
Is there a Theme.Holo in your style directory? Else you might want to use #android:style/Theme.Holo
I'm studying how to use custom theme in android application. After I create a style.xml, and input below xml strings.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Light">
<item name="editTextColor">#00f</item>
</style>
</resources>
Eclipse gave an error when I run the project, it can not find the attribute "editTextColor", but in the sdkpath\platforms\android-17\data\res\values\themes.xml, it does use "editTextColor" attribute.
When I changed the editTextColor, the application works.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Light">
<item name="android:editTextColor">#00f</item>
</style>
</resources>
Can anyone tell me why please? Thank you very much.
While inside sdkpath\platforms\android-17\data\res\values\themes.xml, it is referencing the value directly means inside android platform itself, but while you are trying to reference it inside your application you have to reference it using android:editTextColor because you are using it outside android platform itself and overriding its value.Hope you got some idea.
I'm trying to learn something about styles and themes for Android. I've found that, if I add the android:theme attribute in the manifest for Application or Activity, style is applied to the entire app/activity. I think it would be useful to be able to define a style that is applied for example only to buttons. Do you know if there is a way to apply a certain style only for a certain kind on Views, as in CSS?
Here's a general example:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomButton" parent="#android:style/Widget.Button">
<item name="android:textColor">#FF0000</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:buttonStyle>#style/CustomButton</item>
</style>
</resources>
It's easy to do, just read the official reference:
http://developer.android.com/guide/topics/ui/themes.html
EDIT
Obviously you'll need to specify the style you create on each button/view you want it to be applied (like in css, for the class attribute)