2015-04-20 135 views
1

我試圖在操作欄上顯示一個攝像頭圖標,但它不起作用。菜單顯示並正常工作,但相機圖標不顯示。你能幫我麼?圖標不顯示在操作欄 - Android

預先感謝您。

菜單代碼:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" > 

<item android:id="@+id/action_camera" 
    android:orderInCategory="0" 
    android:icon="@drawable/ic_action_camera" 
    android:title="@string/action_camera" 
    app:showAsAction="always" /> 

<item android:id="@+id/action_delete" 
    android:title="@string/action_delete" 
    app:showAsAction="never" /> 

</menu> 

清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="br.com.cfb.daily_selfie" > 

<uses-permission android:name="android.permission.VIBRATE" /> 

<uses-feature 
    android:name="android.hardware.camera" 
    android:required="true" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_action_camera" 
    android:label="@string/app_name" 
    android:theme="@style/AppBaseTheme" > 
    <activity 
     android:name=".DailySelfieActivity" 
     android:label="@string/app_name" 
     android:launchMode="singleTop"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name=".DisplayPictureActivity" 
     android:label="@string/title_activity_display_picture" 
     android:parentActivityName=".DailySelfieActivity" > 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="br.com.cfb.daily_selfie.DailySelfieActivity" /> 
    </activity> 

    <receiver android:name=".AlarmNotificationReceiver" > 
    </receiver> 

</application> 

</manifest> 

婁的onCreate()

public class DailySelfieActivity extends ListActivity { 

static final int REQUEST_IMAGE_CAPTURE = 1; 
public final static String EXTRA_MESSAGE = "br.com.cfb.daily_selfie.MESSAGE"; 
private static final String TAG = "DS-DailySelfieActivity"; 
private final static int INTENT_ID = 322; 

private SelfieViewAdapter mAdapter; 
private SelfieRecord mSelfieRecord; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    ListView selfieListView = getListView(); 
    final View footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_view, null, false); 
    selfieListView.addFooterView(footerView); 
    mAdapter = new SelfieViewAdapter(this.getApplicationContext()); 
    loadListAdapter(); 
    setListAdapter(mAdapter); 

    //  Create Alarm to take a selfie 
    Alarm mAlarm = new Alarm(getApplicationContext()); 

    //  Enable filtering when the user types in the virtual keyboard 
    //  selfieListView.setTextFilterEnabled(true); 

    //  Set an setOnItemClickListener on the ListView 
    selfieListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 

    //    Display a Toast message indicting the selected item 
      Toast.makeText(getApplicationContext(), "position = " +position + " id = " +id 
        , Toast.LENGTH_LONG).show(); 
      mSelfieRecord = (SelfieRecord) mAdapter.getItem(position); 
      Toast.makeText(getApplicationContext(), "Date = " +mSelfieRecord.getDate() 
        , Toast.LENGTH_LONG).show(); 
      //    Display Picture 
      Intent intent = new Intent(DailySelfieActivity.this, DisplayPictureActivity.class); 
      Bitmap mPicture = mSelfieRecord.getPicture(); 
      intent.putExtra(EXTRA_MESSAGE, mPicture); 
      startActivity(intent); 
     } 
    }); 
} 

婁OnCreateOptionsMenu

public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu_daily_selfie, menu); 
    return true; 
} 
+0

請張貼您的活動。 –

+0

它是您的可繪製文件夾中的圖標? – acostela

+0

您是否已將菜單文件的名稱添加到'onCreateOptionsMenu'中的'inflater.inflate(R.menu.menu_file_name,menu)'? –

回答

0

ic_menu_camera怎麼樣?儘管我在其他地方看到ic_action_camera的引用,但這並不適合我。我也有機會獲得android:icon="@android:drawable/ic_menu_camera"雖然(注意添加@android:drawable)的

或者,如@acostela指出,要確保它在你的繪製文件夾中只使用 android:icon="@drawable/ic_action_camera"

+0

@Xarep,ic_action_camera它在可繪製目錄中。我也嘗試android:icon =「@ android:drawable/ic_menu_camera」並運行應用程序,圖標仍然不顯示。謝謝。 – Carlos

+1

嗨夥計們,我原來的活動擴展了一個ListView,所以我改變和擴展了ActionBar,它運行良好。 – Carlos

+0

嗯,不知道爲什麼擴展ListActivity會導致這個問題,但很高興你得到它的工作@Carlos – Xakep

0

我原來的Activity正在擴展一個ListView,所以我改變並擴展了ActionBar,它運行良好。

謝謝, 卡洛斯