Java 设置所有活动操作栏文本

Java 设置所有活动操作栏文本,java,android,android-actionbar,Java,Android,Android Actionbar,在我的主要活动中,我有一个编辑文本字段,其中输入的任何内容都会更改actionbar文本 我需要存储该值并将其添加到我的所有其他活动中,这样当用户输入文本时,它会更改所有的操作栏 这是更改设置actionbar文本的代码,但我需要获取存储在getSupportActionBar().setTitle(editTextHouse.getText().toString())中的值并将其添加到所有其他活动中 buttonSet.setOnClickListener(new View.O

在我的主要活动中,我有一个编辑文本字段,其中输入的任何内容都会更改actionbar文本

我需要存储该值并将其添加到我的所有其他活动中,这样当用户输入文本时,它会更改所有的操作栏

这是更改设置actionbar文本的代码,但我需要获取存储在
getSupportActionBar().setTitle(editTextHouse.getText().toString())中的值并将其添加到所有其他活动中

        buttonSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            getSupportActionBar().setTitle(editTextHouse.getText().toString());
            }
        });
试试这个:

        private static final String NAME = "my_pref";
        private static final String ACTION_BAR_TITLE = "action_bar_title";
        private SharedPreferences sharedPreferences;
        private SharedPreferences.Editor editor;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);


          }
...
buttonSet.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                String title = editTextHouse.getText().toString();
                getSupportActionBar().setTitle(title);
                editor = sharedPreferences.edit();
                editor.putString(ACTION_BAR_TITLE, title);
                editor.apply();
                }
            });

...
然后在另一个类似这样的活动中获得标题:

@Override
protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                        sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
                        String title = sharedPreferences.getString(ACTION_BAR_TITLE, "Default Title"); // your title
                        getSupportActionBar().setTitle(title);

                  }