Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将共享操作添加到首选项屏幕_Android_Preferences_Shareactionprovider - Fatal编程技术网

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

Android 将共享操作添加到首选项屏幕,android,preferences,shareactionprovider,Android,Preferences,Shareactionprovider,我只是想在我的首选项屏幕中添加一个ShareAction。我已经创建了一个名为share的首选项类别,我正在尝试将其设置为这样,当您单击share时,它会显示ShareAction。我找不到任何东西来解释如何彻底做到这一点。如果有人知道答案,我们将不胜感激 <PreferenceScreen> <PreferenceCategory android:title ="Share" > <Preference android

我只是想在我的首选项屏幕中添加一个ShareAction。我已经创建了一个名为share的首选项类别,我正在尝试将其设置为这样,当您单击share时,它会显示ShareAction。我找不到任何东西来解释如何彻底做到这一点。如果有人知道答案,我们将不胜感激

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



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

    </Preference>
</PreferenceCategory>

查找文档,查找共享行动提供商的标准方式

我使用图书馆是因为我喜欢它

你可以这样实施

库依赖关系

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);
单击共享操作按钮

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;
            }
        });
    }
优先股=findPreference(“SharePreference”);
share.setOnPreferenceClickListener(新的首选项.OnPreferenceClickListener(){
@凌驾
公共布尔值打开首选项单击(首选项){
最终意图shareIntent=新意图(Intent.ACTION\u SEND);
putExtra(Intent.EXTRA_TEXT,“您要共享的链接或文本”);
shareIntent.setType(“文本/普通”);
IntentPickerSheetView intentPickerSheet=new IntentPickerSheetView(Profile.this,shareIntent,“与朋友共享Fitspur”,new IntentPickerSheetView.OnIntentPickedListener(){
@凌驾
IntentPicked上的公共无效(IntentPickerSheetView.ActivityInfo ActivityInfo){
bottomSheetLayout.dismissSheet();
startActivity(activityInfo.getConcreteIntent(shareIntent));
}
});
//过滤掉内置的共享选项,如蓝牙和beam。
intentPickerSheet.setFilter(新的IntentPickerSheetView.Filter(){
@凌驾
公共布尔包含(IntentPickerSheetView.ActivityInfo信息){
return!info.componentName.getPackageName().startsWith(“com.android”);
}
});
//无正当理由按相反顺序对活动排序
intentPickerSheet.setSortMethod(新的比较器(){
@凌驾
公共int比较(IntentPickerSheetView.ActivityInfo lhs、IntentPickerSheetView.ActivityInfo rhs){
返回右标签比较器(左标签);
}
});
底部板材布局。用板材视图显示(内部板材);
返回false;
}
});
}

这是一个首选项屏幕,因此我没有按钮。您仍然可以在其上实现onClickListner,共享您的布局,以便我能够更详细地告诉您。我认为您无法从首选项执行此操作,您必须在视图中使用菜单项或其他任何内容