gpt4 book ai didi

android - 如何更改警告对话框android中内容文本的颜色

转载 作者:行者123 更新时间:2023-11-29 20:58:12 26 4
gpt4 key购买 nike

我被卡住了,我不知道该怎么做。在我的应用程序中,有一个带有包含图像和文本的 ListView 的 AlertDialog 框,但文本颜色变为白色并且不可见我想更改 ListView 中文本的颜色。

请帮忙...

fragment 如下:

  final String[] items = new String[]{"From Gallery", "From Camera"};
final Integer[] icons = new Integer[]{R.drawable.camera_picker, R.drawable.gallery_picker};
ListAdapter adapter = new CameraPickAdapter(StataComplaintActivity.this, items, icons);
final AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT);
//AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.CustomAlertDialogTheme));

builder.setTitle("Select Image From")
.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {
loadImageFromGallery();
} else if (item == 1) {
takePictureIntent();
} else {
}
}
}).show();

CameraPickAdapter.java

public class CameraPickAdapter extends ArrayAdapter<String> {

private List<Integer> images;

public CameraPickAdapter(Context context, List<String> items, List<Integer> images) {
super(context, android.R.layout.select_dialog_item, items);
this.images = images;
}

public CameraPickAdapter(Context context, String[] items, Integer[] images) {
super(context, android.R.layout.select_dialog_item, items);
this.images = Arrays.asList(images);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);

textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0);
textView.setCompoundDrawablePadding(
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics()));
return view;
}

}

对话框如下:

enter image description here

最佳答案

尝试使用上下文引用为适配器中的 TextView 设置自定义或默认颜色:

private Context context;

在构造函数中初始化上下文实例:

this.context = context;

现在使用上下文引用在 getView() 中设置自定义或默认文本颜色:

textView.setTextColor(context.getResources().getColor(R.color.custom_color_name)); // custom color

textView.setTextColor(context.getResources().getColor(android.R.color.black)); // default color

关于android - 如何更改警告对话框android中内容文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26969619/

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