I'm just starting with android using android studio.
I have created a new project and made some minimal changes based on codes found in a few websites and when I run it, I see the app but I do not see the menu (three dots top to bottom).
I understand that there is supposed to be a menu button which on clicked would show menu but is there a way to ensure that the menu will be shown in the top bar in any case.
menu_main.xml:
<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_settings" android:title="@string/action_settings"
app:showAsAction="never" />
<item android:id="@+id/action_other" android:title="@string/action_other"/>
<item android:id="@+id/action_exit" android:title="@string/action_exit"/>
</menu>
MainActivity:
package com.example.arnab.app;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
boolean handled=false;
int id = item.getItemId();
/*//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);*/
switch (id){
case R.id.action_other:
onClickMenuOther(item);
handled =true;
break;
case R.id.action_exit:
onClickMenuExit(item);
handled =true;
break;
default:
handled=super.onOptionsItemSelected(item);
}
return handled;
}
public void onClickMenuOther(MenuItem item){
Toast toast= Toast.makeText(this, "Other Click", Toast.LENGTH_LONG);
toast.show();
}
public void onClickMenuExit(MenuItem item){
finish();
}
}
Thanks