jun xia
jun xia

Reputation: 137

about android toolbar, how to hide defualt setting menu in toolbar

about android Toolbar, how to hide default setting menu in toolbar

in the this activity i hava set a single icon menu,like this –

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
       android:title=""
       android:id="@+id/menu_add"
       android:icon="@drawable/actionbar_add_icon"
       android:showAsAction="ifRoom">
    </item>
</menu>

it is menu/main_home.xml

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    return super.onCreateOptionsMenu(menu);
}

but it show a three dots menu. i want know why

enter image description here

and how to show sub menu icon image ,it is normal in the Actionbar, but hide in the Toolbar

Upvotes: 1

Views: 2315

Answers (2)

jun xia
jun xia

Reputation: 137

this question is solved use app:showAsAction ="ifRoom" not android:showAsAction ="ifRoom"

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
    android:title=""
    android:id="@+id/menu_button"
    app:actionLayout="@layout/menu_single_button"
    app:showAsAction = "always"
     /></menu>

Upvotes: 2

Gi0rgi0s
Gi0rgi0s

Reputation: 1877

  1. If you want to empty the contents of the menu, go to the res/menu folder and delete the item tags from the menu_main.xml file. You will also need to delete references to the items in onOptionsItemSelected(MenuItem item). The menu dots will disappear if there are no items.

  2. If you want to completely remove the three dots menu, then go to the onCreateOptions(...) method in your code and delete it, or simply remove the getMenuInflater().inflate(...); portion of it. You can safely remove the onOptionsItemSelected(MenuItem item) method as well because it will have no purpose.

  3. The simplest way to make the menu disappear is to have the onCreateOptions(...) method return false.

Upvotes: 6

Related Questions