2014-04-14 4 views
0

현재 공식 튜토리얼에 따라 첫 번째 Android 앱을 개발 중입니다. 는 지금 내Android에서 동작 버튼이 보이지 않습니다.

MainActivity에 액션 버튼을 추가하려고 메신저 :

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu items for use in the action bar 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main_activity_actions, menu); 
    return super.onCreateOptionsMenu(menu); 
} 

고해상도/메뉴/main_activity_actions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <!-- Search, should appear as action button --> 
    <item android:id="@+id/action_search" 
      android:icon="@drawable/ic_action_search" 
      android:title="@string/action_search" 
      android:showAsAction="ifRoom" /> 
    <!-- Settings, should always be in the overflow --> 
    <item android:id="@+id/action_settings" 
      android:title="@string/action_settings" 
      android:showAsAction="never" /> 
</menu> 

응용 프로그램이 오류없이 실행되고, 검색 버튼은 표시되지 않습니다. ic_action_search 아이콘이 res/drawable-*에 올바르게 놓여 있고 action_search/action_settingsstrings.xml에 정의되어 있습니다.

나는 뭔가를 놓친가요?

편집 : 의 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.myfirstapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="19" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.myfirstapp.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.example.myfirstapp.DisplayMessageActivity" 
      android:label="@string/title_activity_display_message" 
      android:parentActivityName="com.example.myfirstapp.MainActivity" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.myfirstapp.MainActivity" /> 
     </activity> 
    </application> 

</manifest> 

styles.xml document

당으로

<resources> 

    <!-- 
     Base application theme, dependent on API level. This theme is replaced 
     by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
    --> 
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
     <!-- 
      Theme customizations available in newer API levels can go in 
      res/values-vXX/styles.xml, while customizations related to 
      backward-compatibility can go here. 
     --> 
    </style> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 

</resources> 
+0

매니페스트에 활동 선언을 앱 테마도 추가 할 수 있습니까? –

+0

'AndroidManifest.xml'코드를 추가했습니다. – Chris

+0

당신의'parent = "android : Theme.Holo.Light.DarkActionBar"'를 설정하고 –

답변

2

앱의 호환성을 위해 지원 라이브러리를 사용하는 경우 Android 2.1,만큼 낮은 버전특성은 android: 네임 스페이스에서 사용할 수 없습니다. 대신이 속성은 지원 라이브러리에 의해 제공되며 사용자 고유의 XML 이름 공간을 정의하고 해당 이름 공간을 속성 접 두부로 사용해야합니다. (사용자 정의 XML 네임 스페이스는 앱 이름을 기반으로해야한다, 그러나 당신이 원하는 당신이 그것을 선언하는 파일의 범위 내에서만 액세스 할 수있는 모든 이름이 될 수 있습니다.) 예를 들면 : 당신이

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:yourapp="http://schemas.android.com/apk/res-auto" > 
    <item android:id="@+id/action_search" 
      android:icon="@drawable/ic_action_search" 
      android:title="@string/action_search" 
      yourapp:showAsAction="ifRoom" /> 
    ... 
</menu> 

main_activity_actions.xml에서 사용자 정의 네임 스페이스가 누락되었습니다. 앱 이름 등으로 yourapp을 제거하십시오.

+0

+1 좋은 결과. 잘 했어. –

관련 문제