如何在App |中的TextView中启用复制和粘贴选项Android Studio

时间:2017-10-25 06:24:10

标签: android android-layout android-studio textview android-studio-2.3

所以我想在我的静态Android应用程序中启用copypaste选项,我尝试了每种方式来启用复制粘贴选项,但每次添加代码时,它都会给我错误和警告整个代码。任何人都可以请帮助。任何人都可以告诉我或编辑这些代码,以便在我的Android应用程序中启用复制和粘贴选项

Activity.xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sample.youtuber.health.SecondActivity">


   <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="19dp"
    android:layout_marginRight="19dp"
    android:layout_marginStart="19dp"
    android:layout_marginTop="18dp"
    >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">


<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    tools:ignore="ContentDescription"
    android:src="@drawable/browse"
    android:scaleType="fitXY"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:id="@+id/textview"
    android:text="@string/How_To_Browse_Deep_Web"
    android:textAlignment="center"
    android:layout_gravity="center"
    />
    </LinearLayout>
</ScrollView>


</RelativeLayout>

Activity.java文件

package com.sample.youtuber.health;

import android.annotation.TargetApi;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class SecondActivity extends ActionBarActivity {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    TextView text = (TextView) findViewById(R.id.textview);
    text.setMovementMethod(LinkMovementMethod.getInstance());

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_second, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
    }
}

2 个答案:

答案 0 :(得分:3)

将此行添加到Textview

android:textIsSelectable="true"

答案 1 :(得分:0)

将此行添加到 textview

 android:longClickable="true"
 android:textIsSelectable="true"

在Java类中编写此行以编程方式设置它。

myTextView.setTextIsSelectable(true);