Add EditText to Toolbar

前端 未结 3 1955
说谎
说谎 2021-02-04 01:11

My Toolbar and EditText look like this:

\"enter

I tried

3条回答
  •  难免孤独
    2021-02-04 01:35

    1. Add the EditText to the Toolbar xml.

    2. Add the Toolbar to your Activity's xml layout, at the top.

    3. Set the toolbar as ActionBar:

      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
      }
      

    This will make the toolbar "become" the ActionBar with EditText inside.

提交回复
热议问题