首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ShowcaseView在DialogFragment之上

ShowcaseView在DialogFragment之上
EN

Stack Overflow用户
提问于 2014-05-27 18:38:46
回答 2查看 2.8K关注 0票数 0

我在安卓应用程序中使用ShowcaseView。我希望能够在ShowcaseView的基础上显示DialogFragment。但对我来说,ShowcaseView显示在DialogFragment下面。

在这个项目的github上有关于这个主题的悬而未决的问题。但我想我会按建议在这里提出要求。文章提到,他解决了这个问题,“使用假活动作为对话片段”。但我不知道那是什么意思。也许这意味着他没有使用DialogFragment,而是使用了Activity并将其显示为DialogFragment?我知道您可以将活动的主题设置为Manifest:android:theme="@android:style/Theme.Dialog"中的对话框。

其他github问题是这里这里

我使用的ShowcaseView的“遗留”版本如下:

代码语言:javascript
复制
ViewTarget target = new ViewTarget(R.id.imageView, getActivity());
ShowcaseView.insertShowcaseView(target, getActivity(), R.string.showcase_title, R.string.showcase_details);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-27 18:38:46

因此,要使ShowcaseViewDialogFragment上正确显示,我们必须将DialogFragment显示为Fragment,而不是将DialogFragment显示为Dialog

DialogFragment中,我们可以有这样的东西:

代码语言:javascript
复制
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;
}

我们可以在这样的活动中展示出来:

代码语言:javascript
复制
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布局可以是:

代码语言:javascript
复制
<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条目可以是:

代码语言:javascript
复制
<activity
    android:name=".activity.MyDialogActivity"
    android:theme="@android:style/Theme.Dialog" />
票数 1
EN

Stack Overflow用户

发布于 2016-03-25 09:36:17

您应该编写添加方法,将Activity更改为DialogFragment

代码语言:javascript
复制
private void show(DialogFragment dialog) {
    ((ViewGroup) dialog.getDialog().getWindow().getDecorView()).addView(this);
}

对我来说很管用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23896656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档