import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TestColor extends Activity{
private static final String TAG = "TestColor" ;

private Button mReturn = null ;
private Button mChangeColor = null ;
private Button mNext = null ;
private TextView mText1 = null ;
private TextView mText2 = null ;
private TextView mText3 = null ;
private Intent mIntent = null ;

private int mNum = 0 ;

protected void onCreate(Bundle savedInstanceState)
{
super .onCreate(savedInstanceState);
setContentView(R.layout.test_color);
initView();
}

private void initView()
{
setTitle(R.string.test_color_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeColor = (Button)findViewById(R.id.but_changecolor);
mNext = (Button)findViewById(R.id.but_next);

mText1 = (TextView)findViewById(R.id.test_color_text1);
mText2 = (TextView)findViewById(R.id.test_color_text2);
mText3 = (TextView)findViewById(R.id.test_color_text3);

mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor. this , MainActivity. class );
startActivity(mIntent);
}
});

mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor. this , TestSd. class );
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeColor.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mNum ++;
changeColor(mNum);

}
});
}

private void changeColor( int num)
{
Log.e(TAG, "num = " + (num% 6 ));
switch (num % 6 )
{
case 0 :
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break ;
case 1 :
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break ;
case 2 :
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break ;
case 3 :
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break ;
case 4 :
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break ;
case 5 :
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break ;
}
}

XML文件:

<?xml version= "1.0" encoding= "utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#383838"
android:orientation="vertical"
android:gravity="center" >

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >

<TextView android:id="@+id/test_color_text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />

</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center" >

<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />

<Button android:id="@+id/but_changecolor"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_changecolor" />

<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>

更多相关文章

  1. Android使用Linux命令执行文件操作
  2. Android 10 文件读写权限申请
  3. android 中如何解析Rss订阅的xml文件
  4. android下载文件保存到sd卡
  5. AndroidManifest.xml文件详解(uses-configuration)
  6. Android对应用程序的资源文件xml解析的源代码在哪里
  7. Android获取SD卡视频音频文件
  8. 【Android】debug 状态下其签名文件 debug.keystore 相关(如何获
  9. Android 文件上传支持拍照录用录视频

随机推荐

  1. Android搜索实时显示功能实现
  2. Android的Google官方设计指南(上)
  3. Android缓存处理
  4. Android(安卓)对于MVVM模式的理解
  5. Android真机测试 连接本地服务器
  6. [Android]如何做一个崩溃率少于千分之三
  7. android NDK开发整合opencv开发——环境
  8. 微信小程序AES加密与解密与android AES加
  9. Android删除UIM卡联系人
  10. Android开发过程中框架是如何搭建的呢