2017-11-02 14 views
-3

나는 안드로이드에서 초보자입니다. 교육용 앱 메뉴를 만들려고합니다. 메뉴가 인쇄되지 않는다는 것을 모릅니다. 안드로이드의 메뉴를 볼 수 없습니다

은 내가

내 활동을 내가 그것을

@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_home, menu); 
    return true; 
} 

을 표시하려고

<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.example.gon.myapplication.HomeActivity"> 
<item 
    android:id="@+id/action_settings" 
    android:orderInCategory="1" 
    android:title="@string/app_name" 
    app:showAsAction="always" /> 
내가 뭔가를해야합니까/home.xml 고해상도/메뉴/메뉴에서 간단한 메뉴가 있습니다 잘못된 ? 너의 도움을 위해서.

+0

변경 앱 : android : showAsAction = "ifRoom" –

+0

''styles'' 파일을'styles'에 먼저 추가하십시오. – Xenolion

+0

질문을 편집하여'style.xml' 코드를 추가하십시오! – Xenolion

답변

0

먼저 활동에 작업 표시 줄 또는 작업 표시 줄이 작업 표시 줄로 있는지 확인하십시오.

return true; 대신 return super.onCreateOptionsMenu(menu);을 사용하십시오.

메뉴 항목에 app:showAsAction="never"도 사용하십시오.

+0

이 속성을 변경하면 아무 것도 수정하지 않습니다. – Mohamed

+0

수정 된 답변 확인. –

+0

여전히 작동하지 않습니다. 새 프로젝트를 만들 때 코드는 이전에 작성한 것과 동일하므로 이해가되지 않습니다. – Mohamed

0

이 시도 :

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Add this line of code 
    super.onCreateOptionsMenu(menu); 

    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_home, menu); 
    return true; 
} 

편집

좋아 당신이 닫는 태그로 메뉴를 닫습니다 잊어 버린 경우이 않습니다이 다음 실수

<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.example.gon.myapplication.HomeActivity"> 
<item 
android:id="@+id/action_settings" 
android:orderInCategory="1" 
android:title="@string/app_name" 
app:showAsAction="always" /> 

//add this 

</menu> 

되지 않는 경우 xml 파일을 다음으로 바꿉니다

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
<item 
android:id="@+id/action_settings" 
android:title="@string/app_name" 
/> 


</menu> 

위와 같이 Java 코드를 정확하게 유지하십시오.

+0

시도해도 아무 것도 바뀌지 않습니다 – Mohamed

+0

@ 모하메드가 편집 된 답변을 확인하십시오 –

+0

여전히 작동하지 않습니다. – Mohamed