I want to change the actionbar title text to whatever is typed in the editText view how would I go about doing this?

So far I have this:


   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_home);

       editTextHouse = findViewById(R.id.edit_text_house);

       ActionBar actionBar = getSupportActionBar(); 
       getSupportActionBar().setTitle(editTextHouse);
       String title = actionBar.getTitle().toString(); ```

4 Answers

2
Arbaz Pirwani On Best Solutions

Hello there you can try this with Button Click

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stack);

    Button buttonClick = findViewById(R.id.buttonClick);
    final EditText editTextData = findViewById(R.id.editTextData);

    buttonClick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        //this require non null for null string crash  
          Objects.requireNonNull(getSupportActionBar()).setTitle(editTextData.getText().toString());
        }
    });
}
0
Ganesh Pokale On

On Edittext textChang actionBar title will be changed, Try this.

editTextHouse .addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // Do some thing now
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                // Do something at this time
              if (s != null && s.length() > 0) 
                getSupportActionBar().setTitle(s.toString());
            }
        });
0
abdullah riaz On

use getSupportActionBar().setTitle(editTextHouse.getText()); for what you are doing

0
Community On
   editTextHouse = findViewById(R.id.edit_text_house);

   String text = editTextHouse.getText().toString();

   actionBar.setTitle(text);

Get text from the edittext into a string then set that string as action bar's title.