我正在制作一个可以加密文本并自动复制文本的应用程序。
这是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("");
}
});