コード例 #1
0
    @SuppressWarnings("deprecation")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      final DialogMenuItem item = contents.get(position);

      LinearLayout ll_item = new LinearLayout(context);
      ll_item.setOrientation(LinearLayout.HORIZONTAL);
      ll_item.setGravity(Gravity.CENTER_VERTICAL);

      ImageView iv_item = new ImageView(context);
      iv_item.setPadding(0, 0, dp2px(15), 0);
      ll_item.addView(iv_item);

      TextView tv_item = new TextView(context);
      tv_item.setLayoutParams(
          new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
      tv_item.setSingleLine(true);
      tv_item.setGravity(Gravity.CENTER);
      tv_item.setTextColor(itemTextColor);
      tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTextSize_SP);
      tv_item.setHeight(dp2px(itemHeight_DP));

      ll_item.addView(tv_item);
      float radius = dp2px(cornerRadius_DP);
      if (isTitleShow) {
        ll_item.setBackgroundDrawable(
            (CornerUtils.listItemSelector(
                radius, Color.TRANSPARENT, itemPressColor, position == contents.size() - 1)));
      } else {
        ll_item.setBackgroundDrawable(
            CornerUtils.listItemSelector(
                radius, Color.TRANSPARENT, itemPressColor, contents.size(), position));
      }

      iv_item.setImageResource(item.resId);
      tv_item.setText(item.operName);
      iv_item.setVisibility(item.resId == 0 ? View.GONE : View.VISIBLE);

      return ll_item;
    }
コード例 #2
0
  @Override
  public boolean setUiBeforShow() {

    if (style == STYLE_DEFAULT) {
      widthScale(0.95f);
    }
    /** title */
    float radius = dp2px(cornerRadius_DP);
    tv_title.setHeight(dp2px(titleHeight));
    tv_title.setBackgroundDrawable(
        CornerUtils.cornerDrawable(
            titleBgColor, new float[] {radius, radius, radius, radius, 0, 0, 0, 0}));
    tv_title.setText(title);
    tv_title.setTextSize(TypedValue.COMPLEX_UNIT_SP, titleTextSize_SP);
    tv_title.setTextColor(titleTextColor);
    tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE);

    /** title underline */
    v_line_title.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, dp2px(dividerHeight_DP)));
    v_line_title.setBackgroundColor(dividerColor);
    v_line_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE);

    /** cancel btn */
    tv_cancel.setHeight(dp2px(itemHeight_DP));
    tv_cancel.setText("取消");
    tv_cancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTextSize_SP);
    tv_cancel.setTextColor(itemTextColor);
    tv_cancel.setBackgroundDrawable(
        CornerUtils.listItemSelector(radius, lvBgColor, itemPressColor, 1, 0));

    tv_cancel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            dismiss();
          }
        });

    /** listview */
    lv.setDivider(new ColorDrawable(dividerColor));
    lv.setDividerHeight(dp2px(dividerHeight_DP));

    if (isTitleShow) {
      lv.setBackgroundDrawable(
          CornerUtils.cornerDrawable(
              lvBgColor, new float[] {0, 0, 0, 0, radius, radius, radius, radius}));
    } else {
      lv.setBackgroundDrawable(CornerUtils.cornerDrawable(lvBgColor, radius));
    }

    if (adapter == null) {
      adapter = new ListDialogAdapter();
    }

    lv.setAdapter(adapter);
    lv.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (onOperItemClickL != null) {
              onOperItemClickL.onOperItemClick(parent, view, position, id);
            }
          }
        });
    if (isLacShow) lv.setLayoutAnimation(lac);

    return false;
  }