2014-08-31 2 views
1

조치 표시 줄이 있는데,이 코드를 사용하면 작업 표시 줄의 메뉴 항목이 표시되지 않는 이유를 알 수 없습니다.항목이 작업 표시 줄에 표시되지 않음

main_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.foo.activity" > 

    <item 
     android:id="@+id/button1" 
     android:icon="@drawable/button1" 
     android:onClick="clickEvent" 
     android:showAsAction="ifRoom|withText" 
     android:title="@string/button1"> 
     <item 
      android:id="@+id/log_out" 
      android:orderInCategory="100" 
      android:showAsAction="never" 
      android:title="@string/log_out"/> 
    </item> 

</menu> 

// create action bar menu 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

는이 보여 alwasy : 사전에

enter image description here

감사합니다.

+0

왜 다른 항목에 항목을 넣으시겠습니까 ??? android : showAsAction = "ifRoom | withText"to android : showAsAction = "always" – MHP

+0

당신의 제안에 따라 @MHP 내가'onCreateOptionMenu'에'inflateException'을 얻었습니다. –

+1

아래 답변은 사실입니다. 항목 – MHP

답변

1

다른 item 내에서 item이 허용되지 않기 때문에 항목을 분리 해보십시오.

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.foo.activity"> 

    <item 
     android:id="@+id/button1" 
     android:icon="@drawable/button1" 
     android:onClick="clickEvent" 
     android:showAsAction="always" 
     android:title="@string/button1"/> 
    <item 
     android:id="@+id/log_out" 
     android:orderInCategory="100" 
     android:showAsAction="never" 
     android:title="@string/log_out"/> 

</menu> 
+0

의 주석을 주셔서 감사합니다. 그러나 XML 안에는 XML 파일의 오류 : 빌드를 중단합니다.라고 말했기 때문에 xml 안에 들어갈 수 없습니다. 끝 부분에 ''을 삽입했습니다. 파일. –

+0

@YokupokuMaioku'/> '를 사용하여 항목 요소에 자식이 없다면 (이는 가질 수 없습니다)' '과 같습니다. 제 예제처럼 올바르게 입력했는지 확인하십시오. – Simas

+0

글쎄, 나는/foot 항목에서주의 산만 오류, 어쨌든 많이 감사합니다. –

관련 문제