Click Button to change the color of TextView
2012-08-05 13:51
549 查看
=============================================
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 .
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 ;
}
};
});
}
}
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 .
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 ;
}
};
});
}
}
相关文章推荐
- How to change the Text color of Menu item in Android?
- How to change the text color of the selected property sheet tab in Visual C++
- How to change the text color on UINavigationBar button items
- In Delphi XE2 FireMonkey - How do i change the color of a button after pressing it
- How to programmatically change the default view of an InfoPath form
- how to change text color of CEikEdwin
- [Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?
- How to change the color of a CEikLabel
- how to put the text on the left of a radio button in android
- How to Control the [Add document] button on the bottom of every view?
- (Sharepoint 2010) Change the background and font color of text for a web part header
- How to change the size of the button of an android checkbox?
- TextView with SingleLine as true and Gravity as Center not passing the events to the ViewPager if it has a Click Event
- how to translate the text of push button
- NSButton how to color the text
- how to translate the text of push button
- How to change tintColor of UIBarButtonItem? [SWIFT]
- How to change the background color of form using C++ - 如何用C++改变窗体的颜色
- how to change the background color of actionbar
- How to avoid adding repeat submit the same data if you click the 'Refresh' button of Browser?