Android 通用Dialog中设置RecyclerView

本文介绍了如何在Android的通用Dialog中集成RecyclerView,通过详细步骤展示了如何创建和使用dialog_recycler_view.xml资源文件,提供了相关代码示例。
摘要由CSDN通过智能技术生成

通用Dialog

public class IOSRecyclerViewDialog{
    private Context context;
    private Dialog dialog;
    private LinearLayout lLayout_bg;
    private TextView txt_title;
    private TextView txt_msg;
    private Button btn_neg;
    private Button btn_pos;
    //private ImageView img_line;
    private Display display;
    private boolean showTitle = false;
    private boolean showMsg = false;
    private boolean showPosBtn = false;
    private boolean showNegBtn = false;
    private View view;
    private FrameLayout frameLayout;

    public IOSRecyclerViewDialog(Context context) {
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    public IOSRecyclerViewDialog builder() {
        view = LayoutInflater.from(context).inflate(R.layout.dialog_recycler_view, null);
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
        txt_title = (TextView) view.findViewById(R.id.txt_title);
        txt_title.setVisibility(View.GONE);
        txt_msg = (TextView) view.findViewById(R.id.txt_msg);
        txt_msg.setVisibility(View.GONE);
        btn_neg = (Button) view.findViewById(R.id.btn_neg);
        btn_neg.setVisibility(View.GONE);
        btn_pos = (Button) view.findViewById(R.id.btn_pos);
        btn_pos.setVisibility(View.GONE);

        frameLayout = (FrameLayout) view.findViewById(R.id.customPanel);

        // ????Dialog????????
        dialog = new Dialog(context, R.style.AlertDialogStyle);
        dialog.setContentView(view);
        dialog.setCancelable(false);
        // ????dialog????????
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display
                .getWidth() * 0.85), LayoutParams.WRAP_CONTENT));

        return this;
    }

    public IOSRecyclerViewDialog setCustomView(View v, LayoutParams params){
        if (frameLayout.getChildCount() > 0)
            frameLayout.removeAllViews();

        txt_msg.setVisibility(View.GONE);
        frameLayout.addView(v, params);
        return this;
    }

    public IOSRecyclerViewDialog setTitle(String title) {
        showTitle = true;
        if ("".equals(title)) {
            txt_title.setText("????");
        } else {
            txt_title.setText(title);
        }
        return this;
    }

    public IOSRecyclerViewDialog setMsg(String msg) {
        frameLayout.setVisibility(View.GONE);
        showMsg = true;
        if ("".equals(msg)) {
            txt_msg.setText("????");
        } 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值