Android:设置警报中文本颜色的格式
一切正常。我的代码如下,复制自谷歌指南。我的问题是,是否可以更改警报中文本的颜色?例如,“RED”字符串应为红色,“Green”字符串应为绿色等。提前致谢。
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(BuilderActivity.this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
Everything works fine. My code as below copied from Google's guide. My problem is, is it possible to change the colour of the text int he Alert? For example "RED" string should be red, "Green" string should be green etc. Thanks in advance.
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(BuilderActivity.this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
..dialoglayout.xml
Try this..
dialoglayout.xml
有可能,尝试向 setSingleChoiceItems(ListAdapter 适配器, int checkItem, DialogInterface.OnClickListener 侦听器)。重写适配器的 getView() 方法并适当更改结果视图的文本颜色。
It is possible, try to provide custom implementation of ListAdapter to the setSingleChoiceItems(ListAdapter adapter, int checkedItem, DialogInterface.OnClickListener listener). Override adapter's getView() method and change text color of resulting view appropriately.