我在安卓应用程序中使用ShowcaseView。我希望能够在ShowcaseView的基础上显示DialogFragment。但对我来说,ShowcaseView显示在DialogFragment下面。
在这个项目的github上有关于这个主题的悬而未决的问题。但我想我会按建议在这里提出要求。这文章提到,他解决了这个问题,“使用假活动作为对话片段”。但我不知道那是什么意思。也许这意味着他没有使用DialogFragment,而是使用了Activity并将其显示为DialogFragment?我知道您可以将活动的主题设置为Manifest:android:theme="@android:style/Theme.Dialog"中的对话框。
我使用的ShowcaseView的“遗留”版本如下:
ViewTarget target = new ViewTarget(R.id.imageView, getActivity());
ShowcaseView.insertShowcaseView(target, getActivity(), R.string.showcase_title, R.string.showcase_details);发布于 2014-05-27 18:38:46
因此,要使ShowcaseView在DialogFragment上正确显示,我们必须将DialogFragment显示为Fragment,而不是将DialogFragment显示为Dialog。
在DialogFragment中,我们可以有这样的东西:
public static class MyDialogFragment extends DialogFragment {
public static MyDialogFragment newInstance() {
return new MyDialogFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.hello_world, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("This is an instance of MyDialogFragment");
return v;
}我们可以在这样的活动中展示出来:
public class MyDialogActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_manager);
if (savedInstanceState == null) {
MyDialogFragment fragment = MyDialogFragment.newInstance();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.frameLayout, fragment, "Some_tag")
.commit();
}
}activity_contact_manager.xml布局可以是:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />AndroidManifest.xml条目可以是:
<activity
android:name=".activity.MyDialogActivity"
android:theme="@android:style/Theme.Dialog" />发布于 2016-03-25 09:36:17
您应该编写添加方法,将Activity更改为DialogFragment
private void show(DialogFragment dialog) {
((ViewGroup) dialog.getDialog().getWindow().getDecorView()).addView(this);
}对我来说很管用。
https://stackoverflow.com/questions/23896656
复制相似问题