Jun 23 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Gabriele | has entered the room |
Mark M. |
hello, Gabriele!
|
Mark M. |
how can I help you today?
|
Gabriele |
Hello Mark! So much time, how are you?
|
Mark M. |
OK, and you?
|
Gabriele |
I'm fine, too, thanks! I'm playing with DayNight themes on Android 4 and higher. Everything is working fine, but android:drawable on item selector is causing a crash
|
Gabriele |
any idea of the reason?
|
Mark M. |
what is the exception, and what code is triggering the crash?
|
Gabriele |
I tell you in a moment :)
|
Jun 23 | 4:00 PM |
Gabriele |
this is the line causing the crash: <item android:state_activated="true" android:drawable="?attr/colorPrimary" />
|
Gabriele |
(launching the emulator...)
|
Mark M. |
I have not tried using a color for `android:drawable` -- are you sure that is supported?
|
Gabriele |
If I use @color it's working, so I thought it is
|
Gabriele |
View paste
(134 more lines)
|
Gabriele |
and this is the stack error
|
Mark M. |
if you're sure that is the line causing this error, then it feels like it cannot find the resource associated with `?attr/colorPrimary`
|
Mark M. |
(ugh, ignore the failed Markdown formatting...)
|
Gabriele |
then maybe it is my fault, let me check
|
Jun 23 | 4:15 PM |
Ahmad M. | has entered the room |
Mark M. |
hello, Ahmad!
|
Ahmad M. |
hello Mark
|
Mark M. |
Gabriele: let me take a question from Ahmed, and I will return to you in a bit
|
Mark M. |
Ahmad: your turn! do you have a question?
|
Ahmad M. |
yes
|
Mark M. |
Ahmad: OK, go ahead!
|
Ahmad M. |
is learning Android’s Architecture Components is importante
|
Mark M. |
it depends a lot on what sorts of apps you wish to write
|
Mark M. |
games, for example, will not use the Architecture Components much
|
Mark M. |
for more "traditional" types of apps, the Architecture Components can be useful
|
Mark M. |
plus, Google will be promoting them very heavily, and so they will be difficult to avoid in some cases
|
Ahmad M. |
ok , i need to use Room Database in my app ,but i have my own SQLite Databse how can i use Room that way ?
|
Mark M. |
you would need to adapt your app to use Room to manage your existing tables
|
Mark M. |
that may be tricky to get right, particularly if your app is already in the hands of users
|
Jun 23 | 4:20 PM |
Mark M. |
Room and other ORMs are easier to use if you start with them, rather than switching to them on an existing project
|
Mark M. |
if there are specific problems that you feel Room will solve for you, where those solutions are worth the effort to change your app, then go ahead and try switching to Room
|
Ahmad M. |
i don't need the users to add info to the database i have the database with it's info
|
Mark M. |
OK, so you are packaging the database with the app? or are you downloading the database from your server?
|
Ahmad M. |
is Room a good platform for that ?
|
Mark M. |
it can be
|
Mark M. |
for example, I have a chapter in my "Android's Architecture Components" book that covers how to package a Room database with an app
|
Ahmad M. |
i think it's new and it may have a lot of Bugs and u know
|
Mark M. |
if you have existing code that works and you like it, then there may be no reason to adopt Room
|
Mark M. |
only change working code if there is something that you expect to gain from the change
|
Jun 23 | 4:25 PM |
Mark M. |
let me take another question from Gabriele, and I will return to you in a little while
|
Mark M. |
Gabriele: back to you! do you have another question?
|
Gabriele |
I'm looking at this item, but to me it seems it can find it (at least in Android Studio), any way to check if this is the problem?
|
Ahmad M. |
that lock good to me thank you for your time (:
|
Mark M. |
Gabriele: try switching from ?attr/colorPrimary to a reference to a color resource or something
|
Mark M. |
Ahmad: you're welcome!
|
Ahmad M. | has left the room |
Gabriele |
I have tried with a color resource, but the same happens
|
Mark M. |
you mean, you get the same crash with the same basic stack trace?
|
Gabriele |
no sorry, with the @color it is working
|
Gabriele |
but then how can I handle different colors based on the theme day/night?
|
Mark M. |
well, I have not played with DayNight themes, so I do not know the specifics of that scenario
|
Mark M. |
it is possible that a StateListDrawable cannot support ?attr syntax
|
Mark M. |
or, it is possible that the syntax is fine, but for some reason ?attr/colorPrimary does not exist in both the day and night themes(?)
|
Jun 23 | 4:30 PM |
Gabriele |
what I would like to achieve is change the background of the selected row of my recyclerview based on the theme
|
Gabriele |
colorPrimary exists
|
Mark M. |
I have not tried using ?attr syntax in a drawable resource, and I have not tried DayNight theme support, so I am not really in position to give you a concrete solution
|
Mark M. |
you might consider trying two drawable resources, instead of one with ?attr, and apply the drawables on a per-theme basis
|
Mark M. |
so, you have a day background, and a night background, and your layout chooses the right one based on some theme setti
|
Mark M. |
er, setting
|
Gabriele |
so loading it from code
|
Mark M. |
no, it could be android:background="?attr/selectorBackground" or something, for some custom theme attribute of yours, I presume
|
Gabriele |
I have tried using android:background, but it still crashes
|
Mark M. |
were you using android:background with a drawable resource with an ?attr value in it, as in the code from earlier in the chat?
|
Mark M. |
or were you using android:background="?attr/..."?
|
Gabriele |
I was using ?attr/
|
Jun 23 | 4:35 PM |
Mark M. |
in the drawable, or in the layout?
|
Gabriele |
in the layout
|
Mark M. |
OK, that should work -- perhaps you were getting a different error in the crash
|
Mark M. |
using ?attr/ syntax in layouts is done fairly often
|
Gabriele |
View paste
(198 more lines)
|
Gabriele |
this is using ?colorPrimary
|
Gabriele |
now I'm trying with android:background=
|
Gabriele |
View paste
(198 more lines)
|
Mark M. |
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
|
Mark M. |
this goes back to my wondering if a color resource works in an <item> in a drawable
|
Gabriele |
but using @color/mycolor it works
|
Jun 23 | 4:40 PM |
Mark M. |
then use @color/mycolor, and have two separate drawables (day, night)
|
Jun 23 | 4:40 PM |
Gabriele |
ok, I'll do like that, thanks
|
Gabriele |
this way it's working
|
Jun 23 | 4:45 PM |
Mark M. |
OK
|
Gabriele |
thanks again :)
|
Mark M. |
you are very welcome!
|
Jun 23 | 4:55 PM |
Gabriele |
see you next time, Mark!
|
Gabriele | has left the room |
Jun 23 | 5:00 PM |
Mark M. | turned off guest access |