Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide action bar 3 dots but display items

I am having an issue where i have 2 items in my action bar (one 'refresh' button and one 'Save' Button, but for some reason they do not show, instead they are nested inside an options menu (3 dots). Would anyone know how to remove the 3 dots menu and display my 2 items? I have tried many things but ultimately I just end up removing all three items. Thanks in advance.

Here is my code

add_event_action.xml (this is my menu xml)

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/action_refresh"
    android:showAsAction="always"
    android:icon="@drawable/ic_action_refresh"
    android:title="Refresh"/>

<item
    android:id="@+id/action_save"
    android:showAsAction="always"
    android:title="@string/save"/>
</menu>

Here is my Java class

public class RandomActivity extends AppCompatActivity {

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

    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // action with ID action_refresh was selected
            case R.id.action_refresh:
                Toast.makeText(this, "Refresh selected", Toast.LENGTH_SHORT)
                        .show();
                break;
            // action with ID action_settings was selected
            case R.id.action_save:
                Toast.makeText(this, "Save selected", Toast.LENGTH_SHORT)
                        .show();
                break;
            default:
                break;
        }

        return true;
    }
}
like image 862
DanielRM Avatar asked Sep 20 '25 18:09

DanielRM


2 Answers

If I understood correctly, you need two menu buttons in your toolbar.

This works for me, place it in your menu.xml:

<item
    android:id="@+id/done"
    android:title="@string/done"
    app:showAsAction="always|withText"/>
like image 109
Obsthändler Avatar answered Sep 22 '25 08:09

Obsthändler


Try to use app:showAsAction instead of android:showAsAction

like image 37
Muthukrishnan Rajendran Avatar answered Sep 22 '25 07:09

Muthukrishnan Rajendran