【问题标题】:createChooser not displaying titlecreateChooser 不显示标题
【发布时间】:2020-12-08 15:26:58
【问题描述】:

在Customadapter.java文件中,这部分代码我已经写在下面了。

当我点击任何列表视图项目时,共享窗口打开,但我看不到 createChooser 中提到的标题“共享使用”。请帮​​助我。

CustomAdapter.java

public View getView(int position, View view, ViewGroup viewGroup) {
        LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v=inflater.inflate(R.layout.custom,null);
        TextView tv1=v.findViewById(R.id.textView);
        final TextView tv2=v.findViewById(R.id.textView2);
        TextView tv3=v.findViewById(R.id.textView3);
        tv1.setText(arrayList.get(position).getId()+"");
        tv2.setText(arrayList.get(position).getName());
        tv3.setText(arrayList.get(position).getAddress());


        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent ();
                intent.setAction(Intent.ACTION_SEND);
                intent.putExtra(Intent.EXTRA_TEXT, tv2.getText().toString());
                intent.setType("text/plain");
                context.startActivity(
                        Intent.createChooser(
                                intent,
                                "Share using"
                        )
                );
            }
        });

        return v;
    }

【问题讨论】:

  • 标题是否出现取决于操作系统版本和可能的设备制造商。
  • 那么如何知道哪些会显示哪些不会呢?
  • 一般来说,你不会。您提供标题,是否显示将取决于具体情况。
  • 在哪里提到为什么不显示?

标签: android android-studio android-intent android-listview android-adapter


【解决方案1】:

根据Intent.createChooser(...)的文档:

@param title 可选的title将在选择器中显示仅当目标操作不是 ACTION_SEND 或 ACTION_SEND_MULTIPLE 时

在您的代码中,您有:

intent.setAction(Intent.ACTION_SEND);

这就是你看不到任何标题的原因。

【讨论】:

  • 如果你通过上面的链接,即使是intent.setAction(Intent.ACTION_SEND),我们仍然可以看到标题。
  • 好吧,在本地测试过,即使ACTION_SEND 也会显示标题,我猜我不应该那么相信 android 文档:/ 文档在这里顺便说一句:developer.android.com/reference/android/content/… 标题是否显示如果您将操作更改为其他?
  • 嘿,你是怎么做到的。请解释一下。
  • 我复制了您的确切代码,并且显示了标题。我没有改变任何东西。我在三星 Galaxy S9 上运行代码。正如@CommonsWare 对您的问题所评论的那样,这可能与硬件有关,我看不出有办法操纵它。
猜你喜欢
  • 1970-01-01
  • 2018-10-14
  • 2011-01-03
  • 2015-11-01
  • 2010-12-28
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多