我有一個editText和我有一個按鈕,改變顏色,大小和字體,所以當將文件保存爲pdf或txt文件時如何才能得到這3件事與文本我只得到正常的黑色文本這是我的代碼風格。如何保存editText的顏色,大小,字體?
size.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txtSpeechInput.setTextSize(25);
txtSpeechInput.setTextColor(Color.rgb(150,0,0));
txtSpeechInput.setTypeface(null, Typeface.BOLD);
保存代碼:
final File externalStorageDir = new File(
Environment
.getExternalStorageDirectory(), "MyVoiceText");
boolean success = true;
if (!externalStorageDir.exists()) {
success = externalStorageDir.mkdirs();
}
if (success) {
final Dialog dialog2 = new Dialog(MainActivity.this);
dialog2.setContentView(R.layout.dialog_save);
dialog2.show();
editsave = (EditText) dialog2.findViewById(R.id.edit_save);
pdf = (Button) dialog2.findViewById(R.id.pdf_save);
pdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pdf.setEnabled(false);
txt.setEnabled(true);
}
});
txt = (Button) dialog2.findViewById(R.id.txt_save);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txt.setEnabled(false);
pdf.setEnabled(true);
}
});
dia_save = (Button) dialog2.findViewById(R.id.dia_save);
dia_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String savename = editsave.getText().toString();
if(!txt.isEnabled()) {
File myFile = new File(externalStorageDir + "/" + savename + ".txt");
File myFile = new File(externalStorageDir + "/" + savename + ".txt");
try {
StringBuffer string = new StringBuffer();
string.append(txtSpeechInput.getText().toString());
Properties properties = new Properties();
// set the properties value
properties.put("text",string.append(txtSpeechInput.getText().toString())); properties.put("textstyle","bold");
properties.put("typeface",txtstyle);
properties.put("etxtColor",txtcolor);
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(string);
myOutWriter.close();
fOut.flush();
fOut.close();
} catch (Exception e) {
}
try {
myFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
dialog2.dismiss();
}else if(!pdf.isEnabled()){
try
{
String savename2 = editsave.getText().toString();
String takeit = txtSpeechInput.getText().toString();
Document document = new Document(PageSize.A4);
Paragraph p = new Paragraph();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory() + "/MyVoiceText/" +savename2+".pdf"));
document.open();
writer.getDirectContent();
p.add(new Phrase(takeit));
document.add(p);
document.close();
Log.d("OK", "done");
} catch (Exception e) {
//LOGGER.error(e.getMessage());
}
重新加載文本文件
File sdcard = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/MyVoiceText/");
//Get the text file
File file = new File(sdcard, String.valueOf(selected));
InputStream input = null;
try {
input = new FileInputStream(file);
Properties prop = new Properties();
// load a properties file
prop.load(input);
}catch (Exception e){
e.printStackTrace();
}
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
}
br.close();
catch (IOException e) {
//You'll need to add proper error handling here
}
改變的TextView的大小,字體和顏色是不同的事情,改變PDF文本的大小,字體和顏色。 – nnn
好吧,這是我的問題如何保存文件的自定義顏色,...,.. – Eazyz
爲此,你可以保持你的文字顏色,文字,文字風格,字體的所有portieres到像TextPojo一類,並保持它在Server或本地數據庫或應用程序上下文中。 –