0

Im trying to do a menu with only one icon, but instead of that icon, i am getting the typican three dots, and inside my option. So, i only want one icon. That is my XML code:

<?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="com.bartek.gestionpea.MainActivity">

    <item
        android:id="@+id/ayuda"
        android:icon="@android:drawable/ic_dialog_info"
        android:title="Ayuda"
        app:showAsAction="ifRoom"/>

</menu>

Here goes my class:

public class MainActivity extends Activity {
    PeniaSQLiteHelper usdbh;

    private SQLiteDatabase db;

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

        getActionBar().setTitle("GESTION");

        Button btnCrearPena = (Button) findViewById(R.id.btncrearpena);

        btnCrearPena.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Intent i = new Intent(MainActivity.this, CrearNueva.class);
                startActivity(i);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_principal, menu);
        return true;
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch (item.getItemId()) {
            case R.id.ayuda:
                return true;
        }
        return super.onMenuItemSelected(featureId, item);
    }
}
user1251007
  • 15,891
  • 14
  • 50
  • 76
Uat
  • 3
  • 7

4 Answers4

1

You are using some things for the native action bar (e.g., inheriting from Activity) and some things for the appcompat-v7 action bar backport (e.g., app:showAsAction). Choose one and stick with it:

  • If you wish to use the native action bar, use android:showAsAction

  • If you wish to use the appcompat-v7 action bar backport, inherit from AppCompatActivity (in the latest appcompat-v7) or ActionBarActivity (for prior versions of appcompat-v7)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • If i write android:showAsAction i get an error who says "should use app:showAsAction", so, i dont know really what to do. Thanks for the answer anyway mate :) – Uat Apr 28 '15 at 14:23
  • @Uat: If you want to use the native action bar, also get rid of your `appcompat-v7` dependency and anything else that is using it (e.g., your activity theme). Again, you need to choose **one** implementation of the action bar **and stick with it**, not mix and match from multiple implementations. – CommonsWare Apr 28 '15 at 14:25
  • Understood, thanks for your help! I cant give you votes because i dont have so much reputation yet, but thanks anyway :)) – Uat Apr 28 '15 at 14:30
0

Since you use the standard Activity, try this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/ayuda"
        android:icon="@android:drawable/ic_dialog_info"
        android:title="Ayuda"
        android:showAsAction="always" />

</menu>
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
  • Thanks for the answer, i have tryed that code right now, and stil dont work. I have tryed almost everything inside the showAsAction, and i only see the 3 dots with my options inside. Thanks anyway! – Uat Apr 28 '15 at 14:08
  • Can you please post the code of your Activity class? You can directly edit the question. Thanks – Mattia Maestrini Apr 28 '15 at 14:13
  • Done, alredy psoted my class. ;) – Uat Apr 28 '15 at 14:18
  • The same that i have said to CommonsWare, if i do android:showAsAction i get an error who says "should use app:showAsAction". – Uat Apr 28 '15 at 14:24
  • It's not an error, you can build anyway. You have this warning because you referenced appcompat-v7 but you don't use it. – Mattia Maestrini Apr 28 '15 at 14:25
0

You can modify the app theme (in themes.xml):

 <!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>

<!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme -->
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/your_icon_here</item>
    <item name="android:background">?android:attr/actionBarItemBackground</item>
    <item name="android:contentDescription">"options"</item>
</style>

More info here

Community
  • 1
  • 1
DavidL
  • 1,120
  • 1
  • 15
  • 34
0

Note that when using appcompat themes, you sometimes need to set xml attibutes twice:

once with and once without the android namespace

    <item name="android:windowNoTitle">true</item>
    <item name="windowNoTitle">true</item>