So, I am a beginner, I study programming on Android by the book and there was a problem with the action panel. I can’t add a single button there (I can only click on the ellipsis where the list with my item ). As I understand it, to add a button to the panel, you need to create a menu folder in which to create the XML file, let's say menu_main , write the necessary code and add an item , in which specify showAsAction , id , etc. Further in the activity, create onCreateOptionsMenu() , through the inflater to bind the menu and it should seem like everything will turn out. I will attach my code:

Menu:

 <?xml version="1.0" encoding="utf-8"?> <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" tools:context=".MainActivity"> <item android:id="@+id/action_create_order" android:orderInCategory="1" android:title="@string/action_create_order" android:icon="@drawable/ic_create_black" app:showAsAction="always"/> <item android:id="@+id/action_settings" android:orderInCategory="2" android:title="action_settings" app:showAsAction="always" /> </menu> 

Activity:

 package com.hfad.bitsandpizzas; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.action_create_order: // Действие return true; case R.id.action_settings: // Действие return true; default: return super.onOptionsItemSelected(item); } } } 

This is what the emulator outputs, by the way, minSDK = 17, if that matters. On my Galaxy S4, this trot point is not in sight, the button is responsible for it. enter image description here

  • The problem is not very clear - is it not working on your device, emulator or studio studio previewer? And what exactly does not work? - Yuriy SPb
  • one
    Maybe try not Activity , but AppCompatActivity . - VAndrJ
  • @YuriySPb anywhere. I need a button with an icon on the panel, and as a result, the item appears in the list when clicking on the ellipsis - Ivan
  • @Ivan, try AppCompatActivity instead of Activity. and do not test performance in the previewer. - Yuriy SPb
  • one
    Change your parent theme to Theme.AppCompat - Yuriy SPb

2 answers 2

You need to change the Theme.AppCompat to AppCompatActivity and change the parent theme in the styles to Theme.AppCompat

    Try this:

     app:showAsAction="ifRoom" 
    • I tried, nothing sensible came of it. The problem was the class of the heir and the topic - Ivan