简体   繁体   中英

Android Studio, Watch Face On tap - show Canvas 2, hide canvas1

I'm new here so if I've failed to do something do tell me. Anyway.

I been learning to make wear apps, and heard that watch faces were a good place to start learning.

I've made the date appear and added time, showing battery so on and so forth. But then I wanted to handle touch events. Getting it to acknowledge a tap event I understand, but what I want it to do is on tap to hide the date and the show the time. And visa versa.

I know how to do it logical but don't know "HOW" To do it. If that makes sense, in LUA I would have to create a var and name it say "screen one" , and then change " opacity to -1 == screen one" on the date then "opacity to 100" for on tap to transition screen two. (this isn't exact code but I know what I mean) is it a similar thing in Java?

Say:

if (Canvas == canvas1) {
  canvas2.drawText(color.TRANSPARENT)
}else{
  canvas2.drawText()
  canvas1.drawText(color.TRANSPARENT)

and resting that code into the tap handler? (not that exact code, because this doesn't register)

Or is it more like javascript? Setting up a function. And then In the tap handler having an "onclick" being called ?

SAY, In js it be:

function hide (elements) {
  elements = elements.length ? elements : [elements];
  for (var index = 0; index < elements.length; index++) {
    elements[index].style.display = 'none';
 }
}

onClick(hide) 

Is what I'm suggesting possible? I don't see why not. Or am I just comming at it from wrong angle? My limited knowledge of Java means I'm not sure how to code it the way I want.

Incase there is any confusion. All I want to do is on tap show the time and hide the date. And if the date is showing hide date and then show time.

Any help be greatly appreciated

Thank you for the people who edited my code. I managed to solve my problem my self. I was looking to far out so I thought about how I'd do it in LUA, and slaped my self.

It may not be correct way to do it but it works. I made a int called it screen and = to "1" The just made a simple if statement asking it was screen is equal to "1" change text color to transparent for date and change color of time to red, then set screen = "2" then else if do opposite.

It works :). Lol.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM