Android开发实例之改变背景颜色Word格式.docx
《Android开发实例之改变背景颜色Word格式.docx》由会员分享,可在线阅读,更多相关《Android开发实例之改变背景颜色Word格式.docx(11页珍藏版)》请在冰点文库上搜索。
<
?
xmlversion="
1.0"
encoding="
utf-8"
>
LinearLayoutxmlns:
android="
android:
layout_width="
fill_parent"
layout_height="
orientation="
vertical"
id="
@+id/bgll"
<
!
—-注意在此添加LinearLayout的id-->
background="
#FFFFFFFF"
<
LinearLayout
match_parent"
wrap_content"
horizontal"
>
TextView
style="
@style/alpha"
text="
@string/alpha"
layout_gravity="
center"
/>
SeekBar
@+id/alpha"
150dp"
layout_weight="
0.5"
max="
255"
progress="
128"
/LinearLayout>
@style/red"
@string/red"
@+id/red"
@style/green"
@string/green"
@+id/green"
@style/blue"
@string/blue"
@+id/blue"
@+id/talpha"
透明度:
/>
@+id/tred"
红色值:
@+id/tgreen"
绿色值:
@+id/tblue"
蓝色值:
@+id/tcurrent"
当前值:
颜色值:
"
textColor="
#FF000000"
textSize="
25px"
Button
@+id/btnQuit"
@string/quit"
(2)程序文件:
ChangeBGColorActivity.java
packagecom.minthen.lily;
importandroid.app.Activity;
importandroid.graphics.Color;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.LinearLayout;
importandroid.widget.SeekBar;
importandroid.widget.TextView;
publicclassChangeBGColorActivityextendsActivityimplements
SeekBar.OnSeekBarChangeListener{
/**Calledwhentheactivityisfirstcreated.*/
privateSeekBaralpha,red,green,blue;
privateTextViewtalpha,tred,tgreen,tblue;
privateTextViewtcurrent;
publicstaticintiAlpha,iRed,iGreen,iBlue;
privateButtonbtnQuit;
LinearLayoutbgll;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bgll=(LinearLayout)findViewById(R.id.bgll);
this.setTitle(R.string.title);
btnQuit=(Button)findViewById(R.id.btnQuit);
btnQuit.setOnClickListener(newButton.OnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
ChangeBGColorActivity.this.finish();
}
});
alpha=(SeekBar)findViewById(R.id.alpha);
red=(SeekBar)findViewById(R.id.red);
green=(SeekBar)findViewById(R.id.green);
blue=(SeekBar)findViewById(R.id.blue);
talpha=(TextView)findViewById(R.id.talpha);
tred=(TextView)findViewById(R.id.tred);
tgreen=(TextView)findViewById(R.id.tgreen);
tblue=(TextView)findViewById(R.id.tblue);
tcurrent=(TextView)findViewById(R.id.tcurrent);
iAlpha=alpha.getProgress();
iRed=red.getProgress();
iGreen=green.getProgress();
iBlue=blue.getProgress();
alpha.setOnSeekBarChangeListener(this);
red.setOnSeekBarChangeListener(this);
green.setOnSeekBarChangeListener(this);
blue.setOnSeekBarChangeListener(this);
}
privatevoidChangeBGColor(){
tred.setText("
+iRed+"
或0x"
+Integer.toHexString(iRed));
talpha.setText("
+iAlpha+"
+Integer.toHexString(iAlpha));
tgreen.setText("
+iGreen+"
+Integer.toHexString(iGreen));
tblue.setText("
+iBlue+"
+Integer.toHexString(iBlue));
bgll.setBackgroundColor(Color.argb(iAlpha,iRed,iGreen,iBlue));
btnQuit.setTextColor(Color.argb(iAlpha,iRed,iGreen,iBlue));
btnQuit.setBackgroundColor(Color.argb(255-iAlpha,255-iRed,0xFF-iGreen,0xFF-iBlue));
tcurrent.setTextColor(Color.argb(255,255-iRed,0xFF-iGreen,0xFF-iBlue));
tcurrent.setText("
当前值:
+"
+Integer.toHexString(128)+"
\n颜色值:
+Color.argb(iAlpha,iRed,iGreen,iBlue)+"
+
"
\n或0x"
+Integer.toHexString(Color.argb(iAlpha,iRed,iGreen,iBlue)));
protectedvoidonStart(){
//TODOAuto-generatedmethodstub
super.onStart();
ChangeBGColor();
publicvoidonProgressChanged(SeekBarseekBar,intprogress,booleanarg2){
if(seekBar==alpha){
iAlpha=progress;
}
if(seekBar==red){
iRed=progress;
if(seekBar==green){
iGreen=progress;
if(seekBar==blue){
iBlue=progress;
publicvoidonStartTrackingTouch(SeekBarseekBar){
publicvoidonStopTrackingTouch(SeekBarseekBar){
}