Tôi có một ShareActionProvider cùng với một số tùy chọn khác trong ActionBar của mình. Tuy nhiên có vẻ như ShareActionProvider có vấn đề hiển thị đúng khi lần đầu tiên được hiển thị ở chế độ dọc và không thể nhấp vào lần hiển thị đầu tiên. Một thay đổi định hướng tái hiện màn hình và sau đó tất cả các tùy chọn được cho là hiển thị có thể nhìn thấy và khi quay lại ActionBar lại hiển thị lại nhưng lần này nó cũng hiển thị đúng ở chế độ dọc.ShareActionProvider không thể nhấp và không hiển thị đúng trên lần hiển thị đầu tiên
Tôi đã kèm theo một hình ảnh mô tả tình hình:
Tùy chọn chia sẻ không trả lại đúng, nó cần phải có một biểu tượng bên cạnh nó và nếu nó không phù hợp với bố trí, nó nên trở thành menu 3 dấu chấm.
Sau khi định hướng tất cả các tùy chọn hiển thị như mong đợi.
Quay trở lại chân dung để hiển thị lại ActionBar và bây giờ menu 3 dấu chấm xuất hiện khi cần và có thể nhấp.
Mọi ý tưởng về những gì đang diễn ra ở đây?
Đây là XML của tôi:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item_delete"
android:icon="@android:drawable/ic_menu_delete"
android:showAsAction="ifRoom|withText"
android:title="Delete"
android:visible="false"/>
<item
android:id="@+id/item_edit"
android:icon="@android:drawable/ic_menu_edit"
android:showAsAction="ifRoom|withText"
android:title="Edit"
android:visible="false"/>
<item
android:id="@+id/item_share"
android:actionProviderClass="android.widget.ShareActionProvider"
android:showAsAction="ifRoom|withText"
android:title="Share"
android:visible="false"/>
<item
android:id="@+id/item_save"
android:icon="@android:drawable/ic_menu_save"
android:showAsAction="ifRoom|withText"
android:title="Save"
android:visible="false"/>
<item
android:id="@+id/menu_search"
android:actionViewClass="android.widget.SearchView"
android:icon="@android:drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:title="@string/menu_search"
android:visible="false"/>
</menu>
và đây là cách tôi xử lý menu tùy chọn trong một Fragment:
/**
* Hook into the OptionsMenu and add an Edit, Delete and Share option.
*/
@Override
public void onPrepareOptionsMenu(Menu menu) {
MenuItem deleteItem = menu.findItem(R.id.item_delete);
deleteItem.setVisible(true);
MenuItem editItem = menu.findItem(R.id.item_edit);
editItem.setVisible(true);
MenuItem shareItem = menu.findItem(R.id.item_share);
shareItem.setVisible(true);
shareActionProvider = (ShareActionProvider) shareItem.getActionProvider();
shareActionProvider.setShareIntent(getShareIntent());
super.onPrepareOptionsMenu(menu);
}
/**
* Builds an intent that takes the path for the image and passes it to
* the sharing mechanism as a stream built on the URI of the image path.
* @return the intent to share the image as a stream
*/
private Intent getShareIntent()
{
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + receipt.getPhoto()));
shareIntent.setType("image/jpeg");
return shareIntent;
}
Rất thú vị! Tôi sẽ xem xét điều này ngay sau khi tôi nhận được một số thời gian rảnh rỗi. Cảm ơn! – span