在 TextView Android 中选择和复制文本 [英] Select and copy text in a TextView Android

查看:36
本文介绍了在 TextView Android 中选择和复制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道还有一个和这个类似的问题,但仍然没有回答对我有用.

I know there is another question just like this one but still haven't answer working for me.

我的片段中有一个 TextView,里面有信息.它是一个带有滚动条的长文本视图.我想复制粘贴一些信息,但无法选择和复制.

I have a TextView in my fragment with informations inside.It's a long textview with a scrolling bar. I want to copy paste some information but can't select and copy.

有我的 TextView :

There is my TextView :

<TextView
            android:id="@+id/tv_observ_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="40dp"
            android:textIsSelectable="true"
            android:layout_marginEnd="5dp"
            android:textColor="@android:color/black"
            android:scrollbars="vertical"
            android:enabled="true"
            android:focusable="true"
            android:longClickable="true"
            android:text="Info pratiques " />

我可以复制所有 TextView 的,但我只想要一些信息.

I'm able to copy all the TextView's but I only want some information.

谢谢

编辑

这是所有的布局,它可能会有所帮助:

This is all the layout, it may help :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments_info_client.Coordonne_client"
    android:orientation="vertical">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
        android:orientation="horizontal">

    <TextView
        android:id="@+id/tv_nom_cli"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:textColor="@android:color/black"
        android:text="Nom client"
        android:textStyle="bold">


    </TextView>
        <TextView
            android:id="@+id/tv_codeP_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"
            android:text="Code postal client"
            android:layout_marginStart="10dp">
        </TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="5dp">

        <TextView
            android:id="@+id/tv_adresse_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Adresse Client"
            android:textStyle="bold"
            android:textColor="@android:color/black"
             />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp">

        <TextView
            android:id="@+id/tv_ville_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"
            android:layout_marginLeft="10dp"
            android:text="Ville Client"
            android:textStyle="bold"></TextView>

        <TextView
            android:id="@+id/tv_tel_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Tel Client"
            android:textStyle="bold"
            android:textColor="@android:color/black"
             ></TextView>
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imgBtn_tel_client"
            android:src="@drawable/call_answer"></ImageButton>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv_nb_hab"
            android:text="Nombre habitants : "
            android:layout_marginTop="10dp"
            android:textStyle="bold"
            android:textColor="@android:color/black"
            android:layout_marginLeft="10dp">

        </TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tv_observ_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="40dp"
            android:textIsSelectable="true"
            android:layout_marginEnd="5dp"
            android:textColor="@android:color/black"
            android:scrollbars="vertical"
            android:enabled="true"
            android:focusable="true"
            android:longClickable="true"
            android:text="Info pratiques " />
    </LinearLayout>
</LinearLayout>

此文本视图在一个片段中,此片段由具有不同选项卡的 viewpager 适配器处理,我想知道这种情况是否由于滑动操作而无法为文本视图提供可聚焦(和可选).希望能帮到你

This textview is in a fragment, this fragment is handle by a viewpager adapter with differents tabs, I wonder if this case can't give the focusable(and selectable) to the textview because of the swipe action. Hope it's will help

推荐答案

好吧,我自己发现了问题,我无法选择,因为我有一个

Ok so, I found the problem by myself, I wasn't able to select because i have a

setMovementMethod(new ScrollingMovementMethod());

我试图删除这个,它的工作.谢谢你的帮助

I tried to delete this one and it's work. Thx for ur help

这篇关于在 TextView Android 中选择和复制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆