【问题标题】:How to get the Share and Find Options when select the textview in Android在Android中选择文本视图时如何获取共享和查找选项
【发布时间】:2014-03-29 05:03:07
【问题描述】:

我在 textview 中使用以下标签来复制文本。

android:textIsSelectable="true"

当我选择文本视图时,我得到以下屏幕。

但是,如何获得如下屏幕所示的“查找和共享”选项。

【问题讨论】:

  • 查找选项的作用是什么?

标签: android textview android-textattributes


【解决方案1】:

你必须自己实现它:

当点击/长按文本时,显示您的弹出窗口。

我可能会这样做,在文本上使用OnLongClickListener()

http://developer.android.com/reference/android/view/View.html#setOnLongClickListener(android.view.View.OnLongClickListener)

【讨论】:

  • 是否可以选择用户想要的区域@Thomas
  • 如果textIsSelectable 设置为true,用户将能够选择他们的区域并复制它,但您将无法提供共享功能。如果您使用OnLongClickListener(),您可以显示自己的弹出窗口,但用户将无法选择特定区域。那是一种妥协。您可能可以实现自己的 TextView 行为来提供两者,但这并不容易。
  • 如何选择特定的textarea @Thomas
【解决方案2】:

您必须创建自己的自定义对话框。

所有步骤如下。

创建一个自定义对话框类:

public class CustomizedDialog extends Dialog implements
    android.view.View.OnClickListener {

Context context;

public CustomizedDialog(Context context) {

    super(context);

    this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    //Button aButton = (Button) findViewById(R.id.btnDialogCancel);
}

@Override
public void setContentView(int layoutResID) {
    super.setContentView(layoutResID);
    // TextView objMesaageView = new TextView(context);
}

@Override
public void setTitle(CharSequence title) {

    super.setTitle(title);
}

@Override
public void onClick(View v) {

}

} 然后从你的活动中调用这个类。

CustomizedDialog dialog;
    // open a dialog
private void showDialog() {
    dialog = new CustomizedDialog(getActivity());
    dialog.setContentView(R.layout.dialog_add_number_type);
    dialog.setTitle("Add Black List Number");

       TextView textViewAddNumber=(TextView)dialog.findViewById(R.id.layoutCallLog);

   textViewAddNumber.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // write your code here.

    }
});


    dialog.show();
}

我的布局xml如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#9acd32" >

<RelativeLayout
    android:id="@+id/layoutAddBlockNumbers"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/layoutCallLog"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnTest"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="12dp"
            android:text="test" />

        <TextView
            android:id="@+id/textViewAddNumber"
            style="@style/heading_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="14dp"
            android:text="@string/add_from_call_log" />
    </LinearLayout>

  </RelativeLayout>

【讨论】:

    【解决方案3】:

    经过大量研究,我找到了问题的答案。答案是Android- How can I show text selection on textview?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多