gpt4 book ai didi

android - 将共享操作添加到首选项屏幕

转载 作者:行者123 更新时间:2023-11-29 20:13:41 25 4
gpt4 key购买 nike

我只是想在我的首选项屏幕中添加一个 ShareAction。我已经创建了一个名为 share 的首选项类别,并且我正在努力做到这一点,以便在您单击共享时它会显示 ShareAction。我找不到任何可以解释如何彻底做到这一点的内容。如果有人知道,将不胜感激。

<PreferenceScreen>
<PreferenceCategory android:title ="Share"
>



<Preference
android:title="Share"
android:id="@+id/SharePreference"
android:key="SharePreference">

</Preference>
</PreferenceCategory>

最佳答案

查找文档 here , 用于共享操作提供者的标准方式

我使用 Flipboard's bottomsheet图书馆,因为我喜欢它。

你可以这样实现,

库依赖

compile 'com.flipboard:bottomsheet-core:1.4.3'

布局

<com.flipboard.bottomsheet.BottomSheetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottomsheet"
android:layout_width="match_parent"
android:layout_height="match_parent">

<--ADD YOUR ALL VIEWS IN THIS ROOT>

</com.flipboard.bottomsheet.BottomSheetLayout>

反对

protected BottomSheetLayout bottomSheetLayout;

初始化

bottomSheetLayout = (BottomSheetLayout) findViewById(R.id.bottomsheet);

点击分享 Action 按钮

Preference share= findPreference("shareprefrence");
share.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "your link or text to share");
shareIntent.setType("text/plain");
IntentPickerSheetView intentPickerSheet = new IntentPickerSheetView(Profile.this, shareIntent, "Share Fitspur with your friends", new IntentPickerSheetView.OnIntentPickedListener() {
@Override
public void onIntentPicked(IntentPickerSheetView.ActivityInfo activityInfo) {
bottomSheetLayout.dismissSheet();
startActivity(activityInfo.getConcreteIntent(shareIntent));
}
});
// Filter out built in sharing options such as bluetooth and beam.
intentPickerSheet.setFilter(new IntentPickerSheetView.Filter() {
@Override
public boolean include(IntentPickerSheetView.ActivityInfo info) {
return !info.componentName.getPackageName().startsWith("com.android");
}
});
// Sort activities in reverse order for no good reason
intentPickerSheet.setSortMethod(new Comparator<IntentPickerSheetView.ActivityInfo>() {
@Override
public int compare(IntentPickerSheetView.ActivityInfo lhs, IntentPickerSheetView.ActivityInfo rhs) {
return rhs.label.compareTo(lhs.label);
}
});
bottomSheetLayout.showWithSheetView(intentPickerSheet);
return false;
}
});
}

Licence

关于android - 将共享操作添加到首选项屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com