Android phone displays colorful neon effect

Using the multithreading technology learned before, we make a small example of using Android mobile phone to display a colorful neon effect.

Layout file. Here, only the linear layout file RES / layout / mian.xml with ID is left:

In the RES / values directory, we create a colors.xml file that stores color resources and define seven color resources (red orange yellow green cyan purple):

First get the linear layout manager, then get the screen height, and then create 14 text box components through the for loop and add them to the linear layout manager. Then create and start a new thread, and implement a loop in the rewritten run () method. In this loop, first get a message object and set a message flag for it, then send a message, and finally let the thread rest for 1 second.

In the oncreat () method, create a handler object. In the overridden hanldermessage method, set the color for each text box, and the background color is randomly obtained from the color array. In this way, a small example of colorful neon effect is realized. The specific code is as follows:

MainActivity:

The operation effect is shown in the figure

Isn't it cool!

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>