栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在AlertDialog中更改字体

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在AlertDialog中更改字体

您应该设置布局的自定义视图,而不是设置alertdialog的文本。在执行此操作之前,请修改视图的字体。

TextView mycontent = (TextView) findViewById(R.id.yourid);         mycontent.setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf")

并设置警报对话框的视图,请致电

.setView(mycontent)
setMessage()
尽管据我所知,这不会更改您的标题。

更新 我看到您无法理解我的意思,所以这是一个完整的示例

TextView content = new TextView(this);         content.setText("on another font");         content.setTypeface(Typeface.SANS_SERIF);//Use the first example, if your using a xml generated view     alertDialog.Builder myalert = new alertDialog.Builder(this);         myalert.setTitle("Your title");         myalert.setView(content);         myalert.setNeutralButton("Close dialog", null);         myalert.setCancelable(true);         myalert.show();

这使用的是我们刚刚创建的TextView,并且没有边距等。如果使用易于创建的一种形式的布局文件,则可以自定义所有这些设置,尽管您可以在本示例中将其设置为代码形式。

当然,将字体替换为所需的字体。来自xml的示例TextView可能是:

<TextView        android:id="@+id/yourid"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:padding="8dp"        android:text="your content" />


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570869.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号