I don't know how to solve this. I have an Anko lay...
# anko
j
I don't know how to solve this. I have an Anko layout, inside I have a button with onClick. In the onClick I want to change properties of other layouts, for example I have a verticalLayout whom background I want to change. Giving the verticalLayout a variable does not work. example code verticalLayout{ button.onClick{ // change the background of verticalLayout } }
if I use another Layout on top of the verticalLayour and then assign the veritacl layout to a variable (I can't otherwise) and then try to access the bacgkround in the onClick I get resource not found exception.
Solved it by using View.background = ctx.getDrawable(R.color.XXX) instead. I feel like I have no idea what I'm doing with Anko...
b
If your layout is in a separate file you can give it an id such as
verticalLayout { id = R.id.name }
Then put that id in your res/values/ids file. Then when you want to call it you can say
val bt = find<verticalLayout>(R.id.name)
Finally
bt.background
or whatever you want
👍 1
With Anko since there's not much documentation you kind of have to look at examples projects and the source declarations
👍 1
j
Thank you, that will surely come in handy. What I started to do is look for open soource projects and looking at some apps using Anko (and Kotlin) to get some inspiration.