Skip to main content

All Questions

Filter by
Sorted by
Tagged with
2 votes
1 answer
2k views

How can I access theme color attributes via R.attr.colorPrimary

I'm using Android Studio Electric Eel and I started with a new "Basic Activity" project. It comes with a light and dark theme, /res/values/theme.xml /res/values-night/theme.xml <...
phazei's user avatar
  • 5,429
7 votes
2 answers
2k views

Jetpack Compose. Force switch night/notnight resources

Initially, the theme of my application followed the theme of the system, for convenience I created drawable resources for light and dark themes. Then I implemented the ability to change the theme ...
Tim Yumalin's user avatar
2 votes
2 answers
518 views

Is there a way to override Android's platform attribute value at the app level?

I have a custom viewholder class that gets a color from an attribute in the android namespace in the constructor: int mDefaultPrimaryColor = GetColor(context, android.R.attr.colorPrimary); .... ...
dividebyzero's user avatar
1 vote
1 answer
535 views

How to use a different drawable res folder (for eg. drawable-theme1) when the appTheme is selected as "theme1" from styles.xml? Is this possible?

Currently I am having four themes in my styles.xml file. (theme1, theme2, theme3, theme4). I am having a test_image.xml in both drawable & drawable-theme1 folders. What I need is, for theme1 alone,...
niranj1997's user avatar
1 vote
1 answer
562 views

Use Night resources on Light theme

I'm using the Material Component's dark theme style, everything is working fine but now I need to show a particular view with a different theme to obtain more contrast. I've defined my main theme in ...
materight's user avatar
  • 587
0 votes
1 answer
1k views

When to use homeAsUpIndicator in a toolbar?

I see that in a Toolbar e.g. <androidx.appcompat.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" ...
Jim's user avatar
  • 4,375
6 votes
1 answer
7k views

How to specify android custom color resources: day/night/high contrast

Android supports Day/Night mode with ../values/colors.xml and ../values-night/colors.xml. If I wanted to add another color folder, say for high contrast colors (../values-highconst/colors.xml), ...
display name's user avatar
4 votes
2 answers
2k views

Splash Screen triggers Resources$NotFoundException only on Android 8.1

I followed this tutorial here step by step, it works fine on my API 21 emulator, but on my 27 it crashes as soon as the app loads with: java.lang.RuntimeException: Unable to start activity ...
Michel Feinstein's user avatar
0 votes
1 answer
460 views

Failing to use resource from Android library ("Error retrieving parent for item: No resource found that matches...")

I have an Android library module that defines a theme: <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="Theme.AppCompat.Light"> <item name="windowNoTitle">true</...
SirKnigget's user avatar
  • 3,644
0 votes
3 answers
844 views

How to get a standard color of the neutral button

I am using button with style="?android:attr/buttonBarNeutralButtonStyle" <Button style="?android:attr/buttonBarNeutralButtonStyle" android:layout_width="wrap_content" android:...
Ωmega's user avatar
  • 43.5k
19 votes
4 answers
12k views

How to get a value of color attribute programmatically

When I use resolveAttribute() to find out a color value of ?attr/colorControlNormal, I got 236: TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorControlNormal, ...
Ωmega's user avatar
  • 43.5k
3 votes
1 answer
324 views

How to find reference resource implementation in Android studio?

I mean, is it possible now to see platform's(exact sdk) implementation of reference attr? This time I'm using Android Studio v2.3 and 3.0
Kirill Vashilo's user avatar
13 votes
2 answers
12k views

What's the use of `theme` in `context.getColor` ?

Background Starting from API 23, the small method of getting a color getColor (by just giving it the resource id) of the resources is deprecated: Instead, we are told to use a method that includes a ...
android developer's user avatar
1 vote
2 answers
4k views

Why does ?android:textColorPrimary get different values with different API versions?

I have an app widget with a white background. Some of the text that displays uses ?android:textColorPrimary, some uses ?android:textColorSecondary, and some use colours I've defined. For some reason ...
Michael Vescovo's user avatar
1 vote
1 answer
120 views

Resource reference as attribute value not considered for resource qualification

Assuming related to How to setup night mode drawables as expected I'm trying to implement the new AppCompat DayNight theme in my Android app while providing a theme switch in the settings. Scenario: ...
Julian Os's user avatar
  • 281
1 vote
1 answer
465 views

Change only color when changing Theme

I want to support different themes in my android application. The themes should only differ in two colors. So there are these colors for every theme: Primary Color Secondary Color What I want is, ...
rumpel's user avatar
  • 536
4 votes
1 answer
3k views

How do I apply the style of all TextInputEditText of android application

I want to set custom font size of hint of TextInputEditText. I have an style which I want to apply to my all TextInputEditText. It is not applying on my TextInputEditText. Can anyone help me where I ...
N Sharma's user avatar
  • 34.4k
1 vote
1 answer
68 views

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 ...
R Dev's user avatar
  • 21
79 votes
5 answers
51k views

ResourcesCompat.getDrawable() vs AppCompatResources.getDrawable()

I'm a bit confused with these two APIs. ResourcesCompat.getDrawable(Resources res, int id, Resources.Theme theme) Return a drawable object associated with a particular resource ID and styled for the ...
azizbekian's user avatar
  • 62.1k
1 vote
0 answers
100 views

Android : Getting a color/drawable from anorther theme

I would like to make a theme chooser for my app. In a recyclerView I want to have items background color based on the theme they represent. To be more clear, my themes are like this `<style name="...
liltof's user avatar
  • 2,182
0 votes
1 answer
314 views

Make a API-dependent reference to a theme-style

API 21+: android:background="?android:attr/selectableItemBackgroundBorderless" API <21: android:background="?android:attr/selectableItemBackground" How is it possible? I know the solution that ...
Mir-Ismaili's user avatar
  • 16.7k
4 votes
1 answer
3k views

Resetting CardView's Elevation to the default value (resting elavation)

I want to change a CardView's elevation and reset it later. Currently, I keep the default value of elevation (called resting elevation) as a field value in onCreateView of a Fragment. Later when I ...
hata's user avatar
  • 12.4k
4 votes
1 answer
1k views

Using Holo themes in conjunction with AppCompatActivity

I have a fairly simple app in android which uses the Support Library to provide an Actionbar for devices running on APIs lower than 11, so my main activity extends the AppCompatActivity. My current ...
Timor Gruber's user avatar
3 votes
0 answers
109 views

Api 21 device taking theme from wrong folder

Am I not correct in saying if there is a 'values' folder and a 'values-v19' folder, then a lollipop device will go to the values-v19 folder automatically? This is not happening for me, I have the ...
Daniel Wilson's user avatar
4 votes
0 answers
79 views

How to change theme attribute in code?

Is there anyway to change theme attributes dynamically? For example,set the "android:colorPrimary" attribute for a Theme. I know I can apply different Themes to Activity when it creates, but it ...
teejoe's user avatar
  • 703
-2 votes
1 answer
2k views

Duplicate Resources

I am trying to build my Android app and am recieving this error: Error:Error: Duplicate resources: /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_orange....
Mike's user avatar
  • 6,841
3 votes
1 answer
336 views

Android app: Switch images based on theme from code

I am trying to show a favorite button which as two states (pressed/not pressed). I have 2 sets of images I want to use depending up on the theme selected (Light/Dark). Although i am able to switch ...
Nimesh Madhavan's user avatar
-2 votes
1 answer
24 views

Is there a way to view the final style applied to my application after all inclusions?

My current style is as below, and has a lot of includes. To debug, I want to find out the final element level items that is applied to my app. Is there a way to do it? thanks <style name="Theme....
dowjones123's user avatar
  • 3,837
0 votes
1 answer
743 views

Color Resource with type #0x1d is not valid for android:colorAccent

I have the following error when starting an Activity on Android 5 (on a Nexus 5). 10-23 10:39:43.218 6823-6823/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: eu.elios.gpstracker.app, PID: 6823 ...
David Corsalini's user avatar
4 votes
2 answers
2k views

Extend an external application Style/Theme

I want to define an android style that extends one defined in a different Application/package not imported as library. From the definition of an xml reference to an android resource here: @[<...
Mario Lenci's user avatar
  • 10.5k
4 votes
2 answers
3k views

Can't use referenced color (by theme) in drawable

Consider: styles.xml <style name="BlueTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="theme_color">@color/theme_color_blue</item> </style> attrs.xml &...
Seraphim's's user avatar
  • 12.8k
204 votes
12 answers
138k views

Get color value programmatically when it's a reference (theme)

Consider this: styles.xml <style name="BlueTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="theme_color">@color/theme_color_blue</item> </style> attrs....
Seraphim's's user avatar
  • 12.8k
4 votes
1 answer
5k views

Using private styles (No resource found that matches the given name)

I want to apply a style like the Graphical Layout shows as Theme.DeviceDefault.Dialog.Alert. I know that it's a private style now, and I can't take it as parent. What can I do to have that style to ...
wendigo's user avatar
  • 1,993
0 votes
1 answer
398 views

How to reference an Android theme in preferences?

How do you save a theme in preferences without defining a constant for each theme? The style resource id is pretty straightforward to get and save, but also likely to change in an update. The style ...
hpique's user avatar
  • 120k