问题描述
- Android的expandablelistview的Group展开与收起的背景颜色如何设置?
-
我想要让expandablelistview的group项展开时为绿色,收起时为白色,自己也有找一些网上的例子,很多人都说用Selector,我用了只能在点击时修改颜色,松开就没了,求大神教教我。。
解决方案
public void exportPdf(String title, String[] headers,
Collection dataset, OutputStream out, String pattern) {
// 作为报表的PDF文件,一定要适合打印机的输出打印
Rectangle rectPageSize = new Rectangle(PageSize.A4);// 定义A4页面大小
// rectPageSize = rectPageSize.rotate();// 加上这句可以实现A4页面的横置
Document document = new Document(rectPageSize, 50, 50, 50, 50);// 其余4个参数,设置了页面的4个边距
try {
// 将PDF文档写出到out所关联IO设备上的书写对象
PdfWriter.getInstance(document, out);
// 添加文档元数据信息
document.addTitle(StrHelp.getChinese(title));
document.addSubject("export information");
document.addAuthor("leno");
document.addCreator("leno");
document.addKeywords("pdf itext");
// 定义页头和页尾
HeaderFooter header = new HeaderFooter(new PdfParagraph(title, 20,
true), false);
header.setAlignment(Element.ALIGN_CENTER);
HeaderFooter footer = new HeaderFooter(new Phrase(
"This is page "), new Phrase("."));
footer.setAlignment(Element.ALIGN_CENTER);
document.setHeader(header);
document.setFooter(footer);
// 打开PDF文档
document.open();
// 添加一张表格,使用Table或者PdfPTable
// Table table = new Table(headers.length);
// table.setWidth(16*headers.length);
// //table.setWidths(new float[]{20,20,20,30});
// table.setCellsFitPage(true);
// table.setAutoFillEmptyCells(true);
// table.setAlignment(Table.ALIGN_CENTER);
// table.setBackgroundColor(Color.yellow);
// table.setBorderColor(Color.green);
PdfPTable table = new PdfPTable(headers.length);
// table.setHorizontalAlignment(Element.ALIGN_CENTER);
table.setWidthPercentage(16 * headers.length);
// 产生表格标题行
for (int i = 0; i < headers.length; i++) {
PdfPCell cell = new PdfPCell(new PdfParagraph(headers[i], 14,
true));
cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setBackgroundColor(Color.cyan);
cell.setBorderColor(Color.green);
table.addCell(cell);
}
// 遍历集合数据,产生数据行
Iterator it = dataset.iterator();
int index = 0;
while (it.hasNext()) {
index++;
T t = (T) it.next();
// 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
Field[] fields = t.getClass().getDeclaredFields();
for (short i = 0; i < fields.length; i++) {
PdfPCell cell = null;
Field field = fields[i];
String fieldName = field.getName();
String getMethodName = "get"
+ fieldName.substring(0, 1).toUpperCase()
+ fieldName.substring(1);
try {
Class tCls = t.getClass();
Method getMethod = tCls.getMethod(getMethodName,
new Class[] {});
Object value = getMethod.invoke(t, new Object[] {});
// 判断值的类型后进行强制类型转换
String textValue = null;
if (value instanceof Boolean) {
boolean bValue = (Boolean) value;
textValue = "男";
if (!bValue) {
textValue = "女";
}
} else if (value instanceof Date) {
Date date = (Date) value;
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
textValue = sdf.format(date);
} else if (value instanceof byte[]) {
byte[] bsValue = (byte[]) value;
Image img = Image.getInstance(bsValue);
cell = new PdfPCell(img);
} else {
textValue = value.toString();
}
// 如果不是图片数据,就当做文本处理
if (textValue != null) {
cell = new PdfPCell(new PdfParagraph(textValue));
}
cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setBorderColor(Color.green);
table.addCell(cell);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// 清理资源
}
}
解决方案二:
他不是有监听事件吗,像 setOnGroupExpandListener,在这里处理就行了