Uat
Uat

Reputation: 3

Icon istead of three dots Android Menu

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);
    }
}

Upvotes: 0

Views: 1841

Answers (4)

Mark Stapper
Mark Stapper

Reputation: 51

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>

Upvotes: 0

Mattia Maestrini
Mattia Maestrini

Reputation: 32810

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>

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007544

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)

Upvotes: 1

DavidL
DavidL

Reputation: 1150

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

Upvotes: 0

Related Questions