Android:霓虹灯
16lz
2021-01-23
activity_main.xml
在res/values目录下,创建一个保存颜色资源的color.xml文件<?xml version="1.0" encoding="utf-8"?> #ffff0000 #ffff6600 #ffffff00 #ff00ff00 #ff00ffff #ff0000ff #ff6600ff
接下来是MainActivity.java
import java.util.Random;import android.R.integer;import android.app.Activity;import android.app.ActionBar;import android.app.Fragment;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.Gravity;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.LinearLayout;import android.widget.TextView;import android.os.Build;public class MainActivity extends Activity {private Handler handler;//创建Handler对象private static LinearLayout linearLayout;//整体布局public static TextView[]tv=new TextView[14];//TextView数组public static String str="小白,天冷多加衣。BY:小黄";//TextView显示的文字int []bgColor=new int[]{R.color.color1,R.color.color2,R.color.color3,R.color.color4,R.color.color5,R.color.color6,R.color.color7,};//使用颜色资源private int index=0;//颜色资源数组的下标 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); linearLayout=(LinearLayout)findViewById(R.id.container);//获取线性布局管理器 int height=this.getResources().getDisplayMetrics().heightPixels;//获取屏幕的高度 for (int i = 0; i < tv.length; i++) { tv[i]=new TextView(this);//创建一个文本对象 tv[i].setGravity(Gravity.CENTER);//设置文字显示位置 tv[i].setText(String.valueOf(str.charAt(i)));//设置文本框上的文字 tv[i].setWidth(this.getResources().getDisplayMetrics().widthPixels);//设置文本框的宽度 tv[i].setHeight(height/tv.length);//设置文本框的高度 linearLayout.addView(tv[i]);//添加到布局管理器} Thread t=new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubwhile (!Thread.currentThread().isInterrupted()) {Message m = handler.obtainMessage();//获取一个Messagem.what=0x101;//设置消息标识handler.sendMessage(m);//发送消息try {Thread.sleep(new Random().nextInt(1000));//休眠一秒} catch (InterruptedException e) {// TODO: handle exceptione.printStackTrace();}}}}); t.start();//开启线程 handler=new Handler(){ public void handleMessage(Message msg) {int temp=0;//临时变量if (msg.what==0x101) {for(int i=0;i
在AndroidMainFest.xml文件的标识中,设置android:theme属性,实现全屏显示 android:theme="@android:style/Theme.Black.NoTitleBar"
运行结果如下:更多相关文章
- Android颜色渐变的分隔线(ListView)
- android之【TableLayout布局】
- android 作业1相对布局(拼图)
- android - 头中尾布局
- Android仿计算器布局代码
- android 颜色值 xml
- android的布局练习
- android之【RelativeLayout布局】