|
@@ -0,0 +1,67 @@
|
|
|
|
|
+package com.mgtech.base_library.custom;
|
|
|
|
|
+
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.res.TypedArray;
|
|
|
|
|
+import android.util.AttributeSet;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import androidx.annotation.DrawableRes;
|
|
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
|
+
|
|
|
|
|
+import com.mgtech.base_library.R;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ProjectName: BaseLibrary
|
|
|
|
|
+ * @Package: com.mgtech.base_library.custom
|
|
|
|
|
+ * @ClassName: EmptyView
|
|
|
|
|
+ * @Description: 空布局
|
|
|
|
|
+ * @Author: niusongtao
|
|
|
|
|
+ * @CreateDate: 2020/8/18 11:00
|
|
|
|
|
+ * @UpdateUser: 更新者:niusongtao
|
|
|
|
|
+ * @UpdateDate: 2020/8/18 11:00
|
|
|
|
|
+ * @UpdateRemark: 更新说明:
|
|
|
|
|
+ * @Version: 1.0
|
|
|
|
|
+ */
|
|
|
|
|
+public class EmptyView extends ConstraintLayout {
|
|
|
|
|
+ private ImageView emptyImage;
|
|
|
|
|
+ private TextView emptyText;
|
|
|
|
|
+
|
|
|
|
|
+ public EmptyView(Context context) {
|
|
|
|
|
+ super(context);
|
|
|
|
|
+ initView(context);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public EmptyView(Context context, AttributeSet attrs) {
|
|
|
|
|
+ super(context, attrs);
|
|
|
|
|
+ initView(context);
|
|
|
|
|
+ setView(context, attrs);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initView(Context context){
|
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.layout_empty_view,this);
|
|
|
|
|
+ emptyImage = findViewById(R.id.empty_image);
|
|
|
|
|
+ emptyText = findViewById(R.id.empty_text);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setView(Context context, AttributeSet attrs){
|
|
|
|
|
+ TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.EmptyView);
|
|
|
|
|
+ emptyImage.setBackgroundResource(typedArray.getResourceId(R.styleable.EmptyView_empty_image,0));
|
|
|
|
|
+ emptyText.setText(typedArray.getString(R.styleable.EmptyView_empty_text));
|
|
|
|
|
+ emptyText.setTextColor(typedArray.getColor(R.styleable.EmptyView_empty_text_color,context.getColor(R.color.black_alpha_50)));
|
|
|
|
|
+ typedArray.recycle();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setEmptyImage(@DrawableRes int image){
|
|
|
|
|
+ emptyImage.setBackgroundResource(image);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setEmptyText(String text){
|
|
|
|
|
+ emptyText.setText(text);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|