代码如下:使用的是帧布局
java 代码:
package com.example.home.nihongdeng; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.util.Timer; import java.util.TimerTask; public class MainActivity extends AppCompatActivity { private int currentColor=0; //定义一个颜色组 final int[] colors=new int[]{ R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5, R.color.color6 }; final int[] names=new int[]{ R.id.tv0, R.id.tv1, R.id.tv2, R.id.tv3, R.id.tv4, R.id.tv5 }; TextView[] views=new TextView[names.length]; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { //表明消息来自本程序所发送的 if (msg.what==0x123) { for (int i=0;i<names.length;i++) { views[i].setBackgroundResource(colors[(i+currentColor)%names.length]); } currentColor++; } super.handleMessage(msg); }

这篇博客介绍了如何在Android中实现霓虹灯闪烁的界面效果,使用帧布局和颜色资源完成。作者分享了java代码片段以及color.xml配置,初学者也能轻松上手,体验Android开发的乐趣。
最低0.47元/天 解锁文章
1443

被折叠的 条评论
为什么被折叠?



