如何更改警报对话框的列表视图中的文本颜色? [英] How to change text color which is there in alert dialog's listview?

查看:74
本文介绍了如何更改警报对话框的列表视图中的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,当单击按钮时,显示一个简单的警报对话框

Following is my code to display a simple Alert Dialog, when a button is clicked,

AlertDialog.Builder newImage = new AlertDialog.Builder( MyActivity.this, AlertDialog.THEME_HOLO_LIGHT );
newImage.setTitle( "Select Image" );
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String> (  MyActivity.this, android.R.layout.simple_list_item_1 );
arrayAdapter.add( "Take from camera" );
arrayAdapter.add( "Select from gallery" );

newImage.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() 
{
    @Override
    public void onClick( DialogInterface dialog, int which ) 
    {
    }
});

此代码,显示如下图所示的输出,

This code, display output like below image,


它以白色显示列表项,这就是为什么它不可见的原因。我想将列表项的颜色更改为黑色。

It shows list item in white color, that's why it is not visible. I want to change the list item's color to black.

我应该怎么做?

推荐答案

试试这个

final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String> (  MyActivity.this, android.R.layout.simple_list_item_1 ) {
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    text1.setTextColor(Color.BLACK);
    return view;
  }
};

简单地覆盖 ArrayAdapter 的getview和找到textView更改颜色

Simply override the getview of the ArrayAdapter and find the textView to change the color

这篇关于如何更改警报对话框的列表视图中的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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