I would like to create a new activity that includes more buttons. Each button represents a color. How can I change the action bar (and save) if I click on a button that represents a color (red for example)?
I did something that changes the color of the action bar, but if I go on the home page, the color will change again. Do I need to serialize something? Thanks!
pink.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
getSupportActionBar().setTitle("Pink");
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPink)));
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP){
Window window =getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorAccent));
}
}
});
Button xml.
<Button android:id="@+id/button_pink" android:layout_width="296dp"
android:layout_height="49dp" android:layout_marginTop="26dp"
android:background="@color/colorPink" android:text="pink"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
</android.support.constraint.ConstraintLayout>