Я только начинаю с android, используя андроид-студию.android new project- menu not show
Я создал новый проект и внес минимальные изменения, основанные на кодах, найденных на нескольких веб-сайтах, и когда я его запустил, я вижу приложение, но я не вижу меню (три точки сверху вниз).
Я понимаю, что предполагается, что кнопка меню будет отображаться на экране, но есть способ убедиться, что меню будет отображаться в верхней панели в любом случае.
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();
}
}
Благодарности
Может кто-то пожалуйста, объясните, почему вопрос уцененные ???? – Arnab