-2

i have a problem. I want hide ActionBar and show Menu.

I hided ActionBar with this code.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

and I created Menu with this code.

@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

But problem, not show menu. Can you help me ?

2 Answers2

0

You have to provide your own toolbar and pass it to app's action bar.

Here is a small guide

https://developer.android.com/training/appbar/setting-up.html

sam winston
  • 162
  • 1
  • 13
0
 <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android/colorTansparent"
        app:title=""
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

In Activity

Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
       toolbar.inflateMenu(R.menu.menu);
    toolbar.setOnMenuItemClickListener(item -> {

        switch (item.getItemId()) {
            case R.id.action_0:
                //OnPress of action_0
                return true;
            case R.id.action_1:
               //OnPress of action_0
                return true;
        }

        return false;
    });
ANAND SONI
  • 625
  • 9
  • 13