【问题标题】:Sharing TextView content with relativelayout [closed]与 relativelayout 共享 TextView 内容 [关闭]
【发布时间】:2021-01-31 20:22:24
【问题描述】:

我正在使用relativelayout。不知何故,我找不到分享TextView 内容.. 即使我找到了,我也找不到。我想用一个按钮分享 TextView 内容,你能帮我吗?

我还没有写java代码。

我需要此TextView 的共享代码。注意我正在使用relativelayout

代码主要

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/k"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tw2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_margin="16dp"
        android:shadowColor="#00ccff"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="2"
        android:text=""
        android:textIsSelectable="true"
        android:textSize="30dp" />

</RelativeLayout>

【问题讨论】:

  • 问题不够清楚你想做什么?你得到了什么?
  • 比如我想在WhatsApp上分享TextView的内容
  • android studio 分享按钮
  • 这能回答你的问题吗? How to share text to WhatsApp from my app?
  • 只是这个 WhatsApp 示例。我正在寻找在其他应用中有效的东西

标签: java android android-layout


【解决方案1】:

您可以创建一个隐含的ACTION_SEND Intent 来打开应用选择器,然后选择您要与之共享文本的合适应用。

在活动中使用此方法:

public void shareText(String title, String content) {
    
    // Create an ACTION_SEND Intent
    Intent intent = new Intent(Intent.ACTION_SEND);
    
    // Set the type of the content to "text"
    intent.setType("text/plain");
    
    // Adding extras to the intent (title & content) 
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, content);
    
    startActivity(Intent.createChooser(intent, title));
}

【讨论】:

  • 错误 startActivity(Intent.createChooser(intent, title));。错误:无法从静态连接中引用此方法
  • @Cebom25 删除 static 我现在修好了
  • 我不明白我会在哪里改变
  • 对不起..我刚刚在代码中修复了它,从方法签名中删除了static关键字..我已经这样做了。你可以复制并粘贴它
  • 不幸的是应用程序直接关闭
猜你喜欢
  • 1970-01-01
  • 2021-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-23
相关资源
最近更新 更多