2011-12-05 41 views
6

Tôi đang tạo menu tùy chọn, để tôi sử dụng Android Icon-Resource. Nhưng tôi không thể truy cập chúng, tôi đang làm gì sai. Tôi cần thay đổi điều gì?Không thể truy cập Biểu tượng tài nguyên android/drawable

Dưới đây là Bộ luật của menu.xml tôi

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

    <item android:id="@+id/Videos" 
      android:icon="@android/drawable/ic_menu_view" 
      android:title="Videos" /> 

    <item android:id="@+id/Bio" 
      android:icon="@android/drawable/ic_menu_friendlist" 
      android:title="Biographie" /> 

    <item android:id="@+id/Support" 
      android:icon="@android/drawable/ic_menu_star" 
      android:title="Support" /> 

</menu> 

cảm ơn bạn đã giúp đỡ trước!

Trả lời

23

Bạn đang gần như chính xác, khi truy cập vào các nguồn tài nguyên khuôn khổ bạn phải thêm tiền tố loại tài nguyên với android: từ bạn là using the android package ở đây. Có nghĩa là nó không nên

android:icon="@android/drawable/ic_menu_view" 

nhưng

android:icon="@android:drawable/ic_menu_view" 

thay vì ví dụ (lưu ý ruột kết giữa android và drawable thay vì một dấu gạch chéo).


Cũng lưu ý rằng bạn không thể truy cập một số tài nguyên vì chúng không công khai, chẳng hạn như ic_menu_star bạn đang sử dụng tại đây. Bạn phải sao chép chúng vào các thư mục có thể vẽ của dự án của bạn, điều đó có nghĩa là bạn phải truy cập chúng thông qua @drawable/ic_menu_star bình thường sau khi thực hiện điều đó. Xem this question để tham khảo.

-2

Hãy thử điều này:

<item android:id="@+id/Videos" 
     android:icon="@drawable/ic_menu_view" 
     android:title="Videos" /> 

<item android:id="@+id/Bio" 
     android:icon="@drawable/ic_menu_friendlist" 
     android:title="Biographie" /> 

<item android:id="@+id/Support" 
     android:icon="@drawable/ic_menu_star" 
     android:title="Support" /> 

Tôi nghĩ @ android/drawable/là không chính xác. Bạn nên sử dụng thay vì @ drawable/

Bạn có thể nhìn thấy nó: http://developer.android.com/guide/topics/ui/menus.html

Hope this helps ...

1

thử:

android:icon="@android:drawable/ic_menu_view" 

thay vì:

android:icon="@drawable/ic_menu_view" 
Các vấn đề liên quan