安卓:格式字体的警告对话框 [英] Android: Format Font in Alert Dialog

查看:170
本文介绍了安卓:格式字体的警告对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题。

1)有谁知道,如何应用样式或格式提醒对话框。我目前使用生成器生成器=新AlertDialog.Builder(本); 键,使用 setMessage()方法来设置内容。

1) Does anyone know, how to apply styles or formatting to alert dialog. I currently use Builder builder = new AlertDialog.Builder(this); And use setMessage() method to set the content.

2)另外我想知道如何更改linkify创建的链接的颜色。我不想默认的蓝色。

2) Also I would like to know how to change the color of the links created by linkify. I don't want the default blue color.

推荐答案

Q1。你要充气或自定义并创建一个样式,并应用到AlertDialog

Q1. You have to inflate or customize and create a style and apply to AlertDialog

下面有你如何膨胀的布局,并把它应用到AlertDialog

Heres how you inflate a layout and apply it to AlertDialog

LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);

AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Formatted");
builder.setView(view);

定义在您指定的布局要求的格式和样式。

define all the formatting and styles required in the layout you specified.

您可以通过访问在布局中定义的特定的TextView放大视图即

You can access specific textview defined in the layout using inflated View i.e.

LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);
TextView label=(TextView)view.findViewById(R.id.i_am_from_formatted_layout_lable);

Q2。 机器人:textColorLink =#FF00FF可用于指定链接的颜色

Q2. android:textColorLink="#FF00FF" can be used to specify color of link.

编辑:

样品布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView
   android:id="@+id/text"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="http://www.google.com"
   android:autoLink="web"
   android:textColorLink="#FF00FF"
  />

</LinearLayout>

在您的onCreate(),或在哪里,只要你想打电话AlertDialog

In your onCreate() or where or whenever you want to call AlertDialog

LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Formatted");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.text);

替换上下文对象,如果你是从一些其他的方法调用。

replace this with context object if you are calling from some other method.

这篇关于安卓:格式字体的警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆