目前我的代码允许我通过搜索栏更改主要活动的背景。如何在我的所有其他活动中继续保持这种变化。
E.g。当我移动搜索栏时,我的主要活动中的背景变为红色,但在我的第二个活动中,背景仍为白色。
如何更新它以便我的所有活动都与主要活动的颜色相匹配?
mainactivity.java
public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener{
RelativeLayout myscreen; // SEEKBAR
SeekBar rsb, gsb, bsb; // SEEKBAR
int red, green, blue; //SEEKBAR
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myscreen=(RelativeLayout)findViewById(R.id.mylayout); //SEEKBAR
rsb=(SeekBar)findViewById(R.id.RedSeekBar); //SEEKBAR
gsb=(SeekBar)findViewById(R.id.GreenSeekBar);//SEEKBAR
bsb=(SeekBar)findViewById(R.id.BlueSeekBar); //SEEKBAR
rsb.setOnSeekBarChangeListener(this); //SEEKBAR
gsb.setOnSeekBarChangeListener(this); //SEEKBAR
bsb.setOnSeekBarChangeListener(this); //SEEKBAR
Button gotoscreen2 = (Button)findViewById(R.id.BgoToScreen2); //BUTTON
gotoscreen2.setOnClickListener(new View.OnClickListener() { //BUTTON
@Override
public void onClick(View v) { //BUTTON
// TODO Auto-generated method stub //BUTTON
Intent screen2 = new Intent("com.sunveersinghseera.seekbar.OURSECONDSCREEN");//BUTTON
startActivity(screen2);//BUTTON
}
});
}
public void updatebackground(){ //SEEKBAR
red = rsb.getProgress(); //SEEKBAR
green = gsb.getProgress(); //SEEKBAR
blue = bsb.getProgress(); //SEEKBAR
myscreen.setBackgroundColor(0xff000000+red*0x10000+green*0x100+blue); //SEEKBAR
}
Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
updatebackground();
}
secondpage.java
public class OurSecondScreen extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
}
}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/mylayout"
android:background="#FF0000"
tools:context="com.sunveersinghseera.seekbar.MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change the background" />
<Button
android:id="@+id/BgoToScreen2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
android:text="Go To Screen 2" />
<SeekBar
android:id="@+id/RedSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/GreenSeekBar"
android:layout_below="@+id/textView1"
android:max="255"
android:layout_marginTop="23dp" />
<SeekBar
android:id="@+id/GreenSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:max="255"
android:layout_below="@+id/RedSeekBar" />
<SeekBar
android:id="@+id/BlueSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/GreenSeekBar"
android:max="255"
android:layout_below="@+id/GreenSeekBar" />
</RelativeLayout>
secondpage.xml
<?xml versio`enter code here`n="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mylayout"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the second screen" />
</RelativeLayout>
我认为这与第二页的xml文件有关,但我不太确定。任何帮助将不胜感激。