java - 在android中处理下划线/粗体/斜体文本

标签 java android

我正在使用 jxl api 处理 Excel 文件中的内容并将它们加载到 json 字符串中。然后,我解析 json 字符串并在屏幕上的各种 TextView 中显示内容。如果 Excel 中有任何下划线/粗体/斜体文本,则它不会相应地显示在 TextView 中。有人可以建议如何确保在 Excel 中完成的带有下划线/粗体/斜体的任何文本也显示在 TextView 中。 下面是我用来处理 Excel 文件中的字符串的代码

w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
Cell storyNameCell = sheet.getCell(1,1);
String Title = storyNameCell.getContents();
//get more cells into Strings
//form the json string from all the String contents above

这就是我将上面的 JSON 字符串保存到 Android 设备上的本地文件中的方法

    String FILENAME = getString(R.string.app_name)+"_"+storyTitle;
      FileOutputStream output = openFileOutput(FILENAME,MODE_PRIVATE);
    OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8");
        writer.write(jObjStoryTitle.toString());
        writer.flush();
        writer.close();

最后,我从文件中获取任何 JSON 字符串,以便根据用户请求进行显示。

    BufferedReader in = new BufferedReader(new InputStreamReader(this.getBaseContext().openFileInput( quizFileName), "UTF-8"));
        while ((str = in.readLine()) != null)
            fileContent.append(str);
        fileString = new String(fileContent);
        jObjStoryTitle = new JSONObject(fileString);

最佳答案

我终于能够解决这个问题了。这就是我所做的。 - 使用 apache POI api 在我的 Android 应用程序中读取 xls 文件。 Jxl api 没有帮助,因为它无法识别单元格文本部分中嵌入的任何字体/样式。 -因此,使用 Apache-POI,我可以找出文本的哪一部分包含下划线字符。 -然后我在该部分之前/之后嵌入了 html 标签 - 然后使用Html对象在Textview中显示如下

myTextView.setText(Html.fromHtml(underlinedText));

关于java - 在android中处理下划线/粗体/斜体文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27786417/

相关文章:

java - 使用 SolrJ 查询 Solr 服务器

android - 无法使用runtime.exec重新启动设备

java - 通过 TimerTask 从另一个类更新 Activity 的 TextView 的两个选项

android - 带有比例标签的动画列表在 Marshmallow 中不起作用

android - 删除的 Espresso 测试仍在运行

android json多维数组

java - 在 Retrofit 中使用绝对 URL

java - Android set() 和 setExact() 警报以不正确的时间间隔触发

java - FTP 文件服务器上传警报

java - 如何将文件中的字符串值设置为自定义类变量?