gpt4 book ai didi

java - 如何在 Android 代码中动态地为字符串添加粗体和下划线?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:57 25 4
gpt4 key购买 nike

如何使分行名称:分行编号:分行电话:分行时间设置为粗体和斜体: 在 Java 代码中?数据库数据应保持简单格式。这四个只是其中的标题。在这种(当前)情况下,它以简单格式打印/显示整个数据,用户在读取这些数据时遇到问题。

String branchInfoString = "" ;

// fetching all the database data in a list
List<BranchInfo> dbDataList = _dbHandler.getAllInfo() ;

// getting that data into a string that will be displayed in TextView
for(BranchInfo aBranch : dbDataList ){

branchInfoString = branchInfoString +

"Branch Name: " + aBranch.getBranchName() + "\n" +
"Branch No: " + aBranch.getBranchNo() + "\n" +
"Branch Phone No: " + aBranch.getBranchPhone() + "\n" +
"Branch Timings: " + aBranch.getBranchTiming() + "\n" +

"\n --------------------------------------- \n \n" ;

}

// showing all the branch data in a text_view
setContentView(R.layout.db_branch_list) ;
TextView dbDataView = (TextView)findViewById(R.id.db_branch_list) ;
dbDataView.setText(branchInfoString) ;

最佳答案

是的,您可以使用 HTML 标记装饰 TextView 中的文本。这不仅包括斜体和粗体,还包括字体颜色和其他一些东西。像这样:

branchInfoHtmlString = branchInfoString + 

"<b>Branch Name: " + aBranch.getBranchName() + "</b>\n" +
"<i>Branch No: " + aBranch.getBranchNo() + "</i>\n" +
"<font >Branch Phone No: " + aBranch.getBranchPhone() + "</font>\n" +
"<font color="#FFDDDDDD">Branch Timings: " + aBranch.getBranchTiming() + "</font>\n" +

"\n --------------------------------------- \n \n" ;

}

// showing all the branch data in a text_view
setContentView(R.layout.db_branch_list) ;
TextView dbDataView = (TextView)findViewById(R.id.db_branch_list) ;
dbDataView.setText(Html.fromHtml(branchInfoHtmlString)) ;

并非所有 HTML 标签都受支持,您可以找到标签列表 herehere .

关于java - 如何在 Android 代码中动态地为字符串添加粗体和下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14597031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com