package com.qxcm.moduleutil.widget; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.qxcm.moduleutil.R; /** *@author *@data 2025/5/15 *@description: 当没有数据时展示的view */ public class CommonEmptyView extends FrameLayout { private ImageView ivEmpty; private TextView tvEmptyText; private TextView tvOtherOperation; private LinearLayout layoutEmpty; private OtherOpListener otherOpListener; public CommonEmptyView(@NonNull Context context) { super(context); initViews(); } public CommonEmptyView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); initViews(); } public CommonEmptyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initViews(); } private void initViews() { LayoutInflater.from(getContext()).inflate(R.layout.layout_empty, this); ivEmpty = findViewById(R.id.iv_empty); tvEmptyText = findViewById(R.id.tv_empty_text); tvOtherOperation = findViewById(R.id.tv_other_operation); layoutEmpty = findViewById(R.id.layout_empty); tvOtherOperation.setOnClickListener(v -> otherOpListener.otherClick()); } /** * 设置提示文字 * * @param text */ public void setEmptyText(String text) { if (null != tvEmptyText) { tvEmptyText.setText(text); } } /** * 设置提示文字的颜色 */ public void setTextColor(int color) { if (null != tvEmptyText) { tvEmptyText.setTextColor(color); } } /** * 设置按钮文字 * * @param txt */ public void setBtnText(String txt) { if (null != tvOtherOperation) { tvOtherOperation.setText(txt); tvOtherOperation.setVisibility(VISIBLE); } } /** * 设置占位图 */ public void setImg(int res) { ivEmpty.setImageResource(res); } public void addOnOtherListener(OtherOpListener otherOpListener) { this.otherOpListener = otherOpListener; } public interface OtherOpListener { void otherClick(); } }