Selam zeynep ;
Aşağıdaki kodu incelersen bi bilgi verebilir.
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
RelativeLayout relativeLayout;
Button button;
public static final String renk = "renk";
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.button);
relativeLayout=(RelativeLayout) findViewById(R.id.relative);
sharedpreferences = getSharedPreferences(renk, Context.MODE_PRIVATE);
if(sharedpreferences!=null) {
relativeLayout.setBackgroundColor(sharedpreferences.getInt(renk, Color.GREEN));
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences.Editor editor = sharedpreferences.edit();
int color=Color.RED;
editor.putInt(renk,color);
editor.commit();
relativeLayout.setBackgroundColor(color);
}
});
}
}