zoukankan      html  css  js  c++  java
  • Click Button to change the color of TextView

    =============================================

    Download project link: http://ishare.iask.sina.com.cn/f/33388237.html

    Included Files are :

    ButtonANDTextView.apk
    ButtonANDTextView.zip(Source Code )
    Click Button to change the color of TextView.docx
    result_1.png
    result_2.png

    =============================================

    Click Button to change the color of TextView

    Create an array to store colors ,in the OnClick Method , use the array index to select color to change the color of TextView dynamic .

    clip_image002clip_image004

     

    package button.and.textview;

    import android.app.Activity;

    import android.graphics.Color;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    import android.widget.TextView;

    publicclass ButtonANDTextViewActivity extends Activity

    {

        private Button btn;

        private TextView tv;

        privateint [] colors;

        privateintindex;

        /** Called when the activity is first created. */

        @Override

        publicvoid onCreate(Bundle savedInstanceState)

        {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

           

            /* Find the id of Button and TextView*/

            btn = (Button)findViewById(R.id.changColor);

            tv =(TextView)findViewById(R.id.textView);

           

            /*Create an array to store colors of text*/

            colors = newint []{ Color.RED ,

              Color.BLUE , Color.GREEN , Color.MAGENTA , Color.YELLOW };

            index = 0 ;

           

            /*Change the color of text in the OnClick method of Button .*/

            btn.setOnClickListener(new Button.OnClickListener()

            {

               @Override

               publicvoid onClick(View v)

               {

                  // TODO Auto-generated method stub                    

                      if(index < colors.length )

                      {

                         tv.setTextColor(colors[index] );

                         index++ ;

                      }

                      else

                      {

                         index = 0 ;

                      }

               };

            });             

        }

    }

  • 相关阅读:
    45个非常有用的Oracle查询语句(转自开源中国社区)
    Oracle创建表空间及用户
    table里面,怎么根据checkbox选择的一行中的某个单元格的值是否为空,来判断是否该选中
    点击上传按钮,文件自动上传
    如何给frame标签的src属性以及a标签的href属性自动设值
    Tomcat内存溢出的三种情况及解决办法分析
    Java中判断字符串是否为数字的五种方法
    SSH项目里面 忘记密码的邮件发送功能
    form表单提交时,action怎么带参数
    因为多余jar包,所报的错
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2623803.html
Copyright © 2011-2022 走看看