android studio复制到下一行,android - Android Studio:如何在一行中从TextView或EditText复制文本 - 堆栈内存溢出...

我正在制作一个可以加密文本并自动复制文本的应用程序。

这是XML:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/txt"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Enter Text To Encrypt or To Decrypt"

android:inputType="text" />

android:id="@+id/txtkey"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Enter KEY"

android:inputType="text" />

android:id="@+id/txtsalt"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Enter SALT"

android:inputType="text" />

android:id="@+id/txtres"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Result"

android:clickable="false"

android:inputType="none"

android:singleLine="true" />

android:id="@+id/btnencrypt"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Encrypt" />

android:id="@+id/btndecrypt"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Decrypt" />

android:id="@+id/btnclear"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Clear" />

这是Btnencrypt代码,它进行加密+复制到加密的文本

btnencrypt.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String encrypted = Encrypt(txt.getText().toString(), txtkey.getText().toString(),txtsalt.getText().toString());

txtres.setText(encrypted);

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

ClipData clip = ClipData.newPlainText("label", txtres.getText().toString().trim());

clipboard.setPrimaryClip(clip);

Toast.makeText(getApplicationContext(), "Encrypted Text Copied", Toast.LENGTH_SHORT).show();

txt.setText("");

}

});

当我将加密的文本粘贴到Notepad ++中时,它采用一种奇怪的格式:2行文本和1空行。 我想要的是将整个文本放在一行中,看到下面的图像

编辑:

通过添加.trim(),删除了无用的行,但是Im仍然有2行文本而不是单行

btnencrypt.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String encrypted = Encrypt(txt.getText().toString().trim(), txtkey.getText().toString().trim(),txtsalt.getText().toString().trim());

txtres.setText(encrypted.trim());

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

ClipData clip = ClipData.newPlainText("label", txtres.getText().toString());

clipboard.setPrimaryClip(clip);

Toast.makeText(getApplicationContext(), "Encrypted Text Copied", Toast.LENGTH_SHORT).show();

txt.setText("");

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值