原生布局是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.kimdemon.share.MainActivity">

<EditText
android:id="@+id/yf_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/edit1"/>



<EditText
android:id="@+id/yf_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/edit2"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">



<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
style="@style/button1"
android:onClick="onClick"
android:id="@+id/yf_button1"/>

<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
style="@style/button2"
android:onClick="onClick"
android:id="@+id/yf_button2"/>

</LinearLayout>

</LinearLayout>

Java的代码

package com.example.kimdemon.share;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



public class MainActivity extends AppCompatActivity {
private EditText yf_name;
private EditText yf_age;
private Button yf_button1;
private Button yf_button2;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
yf_name = (EditText)findViewById(R.id.yf_name);
yf_age = (EditText)findViewById(R.id.yf_age);
yf_button1 = (Button)findViewById(R.id.yf_button1);
yf_button2 = (Button)findViewById(R.id.yf_button2);



setContentView(R.layout.activity_main);
}

private void save(String name,String age){
SharedPreferences.Editor editor = getSharedPreferences("data",MODE_PRIVATE).edit();
editor.putString("name",name);
editor.putString("age",age);
editor.commit();
editor.clear();
Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_LONG).show();

}

private void read(){
SharedPreferences pref = getSharedPreferences("data", MODE_PRIVATE);
String yf_name = pref.getString("name","");
String yf_age = pref.getString("age","");
Toast.makeText(MainActivity.this,"我叫"+yf_name+"今年"+yf_age,Toast.LENGTH_LONG).show();
}

public void onClick(View view){
switch (view.getId()){
case R.id.yf_button1:
String  name = yf_name.getText().toString();
String age = yf_age.getText().toString();
save(name,age);
break;
case R.id.yf_button2:
read();
break;
}
}
}