2015-06-30 3 views
-2

Я только начинаю с 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(); 
    } 

} 

Благодарности

+0

Может кто-то пожалуйста, объясните, почему вопрос уцененные ???? – Arnab

ответ

0

Ответ на this решить мою проблему:

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:orderInCategory="100" 
    app:showAsAction="always" 
    android:icon="@drawable/ic_overflow" 
    android:title=""> 
    <menu> 
     <item android:id="@+id/action_other" android:title="@string/action_other"/> 

     <item android:id="@+id/action_exit" android:title="@string/action_exit"/> 


    </menu> 
</item> 
</menu> 
0

В XML, изменить showAsAction="never"always к или ifRoom.

+0

Он отображает все элементы меню в тексте в панели, невозможно ли показывать только три точки, а также щелкнуть или навести на них курсор, все три текста просматриваются один под другим – Arnab