Bạn có thể thử theo dõi Link này.
Kiểm tra điều này và cho tôi biết liệu nó có hoạt động hay không.
Hoặc bạn có thể làm một số việc như thế này.
Tạo menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/next"
android:icon="@drawable/ic_next"
android:title="@string/next" />
<item android:id="@+id/previous"
android:icon="@drawable/ic_previous"
android:title="@string/previous" />
<item android:id="@+id/list"
android:icon="@drawable/ic_list"
android:title="@string/list" />
</menu>
Và bây giờ bạn sẽ có thể thiết lập ICON trên menu
Bây giờ trong CreateOptionMenu
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
Và để truy cập menu.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.next:
Toast.makeText(this, "You have chosen the " + getResources().getString(R.string.next) + " menu option",
Toast.LENGTH_SHORT).show();
return true;
…
default:
return super.onOptionsItemSelected(item);
}
}
Nguồn
2013-02-21 06:21:21
nó một câu hỏi hay. Quá xấu nó không có câu trả lời. Không có phương pháp nào trong số này hoạt động. –