title: SharedPreferences on a Button
body: <p>I am trying to retrieve the <code>editText</code> value and the button color using <code>shared preferences</code>. For the <code>editText</code>, it works very well but the problem is in saving and loading the color of the button. Note that I want to save the current color of the button by <code>onWriteClick</code> method and color the button by its color by <code>onReadClick</code>.</p>
  
  <p>Here what I wrote:</p>
  
  <pre><code>Button btn ;
  EditText c;
  private static final String KEY = "key";
  private SharedPreferences preferences;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  c = (EditText) findViewById(R.id.editText1);
  btn = (Button) findViewById(R.id.button);
  preferences = getSharedPreferences("preferences", Context.MODE_PRIVATE);
           }
  
  //shared preferences
      @SuppressLint("NewApi")
      public void onWriteClick() {
          Editor editor = preferences.edit();
          Editor color = preferences.edit();
          editor.putString(KEY, c.getText().toString());
        //Here is the problem 
         color.putString(KEY, btn.setBackgroundColor("#FFFFF"));
  
          if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.GINGERBREAD) {
              editor.apply();
          } else {
              // This call is synchronous and should be done in a background
              // thread
              editor.commit();
          }
      }
  
      public void onReadClick() {
          String text = preferences.getString(KEY, null);
          c.setText(text);
      }
  }
  </code></pre>
  
  <p>Any Help please</p>