From 9970dc9cb5b74acd84694528a7f37ea8301c1bee Mon Sep 17 00:00:00 2001 From: lixiaojun <16167479@qq.com> Date: Thu, 12 Aug 2021 21:38:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/lxj/demo1/MainActivity.kt | 6 +++--- app/src/main/res/layout/custom_empty.xml | 8 +++++++- .../src/main/java/com/lxj/statelayout/StateLayout.kt | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/lxj/demo1/MainActivity.kt b/app/src/main/java/com/lxj/demo1/MainActivity.kt index 8741d84..7d82d3c 100644 --- a/app/src/main/java/com/lxj/demo1/MainActivity.kt +++ b/app/src/main/java/com/lxj/demo1/MainActivity.kt @@ -101,10 +101,10 @@ class MainActivity : AppCompatActivity() { //测试布局中使用 slInLayout.config( - emptyText = "大萨达所大撒", + emptyIcon = R.mipmap.ic_launcher_round, loadingLayoutId = R.layout.custom_loading2, - errorLayoutId = R.layout.custom_error -// emptyLayoutId = R.layout.custom_empty + errorLayoutId = R.layout.custom_error, + emptyLayoutId = R.layout.custom_empty ) { slInLayout.postDelayed({slInLayout.showEmpty()}, 1000) } slInLayout.showLoading() slInLayout.postDelayed({slInLayout.showContent()}, 2000) diff --git a/app/src/main/res/layout/custom_empty.xml b/app/src/main/res/layout/custom_empty.xml index ad6d5c8..61fedf9 100644 --- a/app/src/main/res/layout/custom_empty.xml +++ b/app/src/main/res/layout/custom_empty.xml @@ -1,11 +1,17 @@ + + diff --git a/statelayout-library/src/main/java/com/lxj/statelayout/StateLayout.kt b/statelayout-library/src/main/java/com/lxj/statelayout/StateLayout.kt index d635a43..6adf386 100644 --- a/statelayout-library/src/main/java/com/lxj/statelayout/StateLayout.kt +++ b/statelayout-library/src/main/java/com/lxj/statelayout/StateLayout.kt @@ -7,6 +7,7 @@ import android.content.Context import android.graphics.Color import androidx.fragment.app.Fragment import android.util.AttributeSet +import android.util.Log import android.view.* import android.widget.FrameLayout import android.widget.ImageView @@ -23,7 +24,7 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr var animDuration = 250L var useContentBgWhenLoading = false //是否在Loading状态使用内容View的背景 var enableLoadingShadow = false //是否启用加载状态时的半透明阴影 - var emptyText: String = "暂无数据" + var emptyText: String = "" var emptyIcon: Int = 0 var enableTouchWhenLoading = false var defaultShowLoading = false @@ -257,9 +258,9 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr val group = emptyView as ViewGroup (0 until group.childCount).forEach { val child = group.getChildAt(it) - if(child is TextView) { + if(child is TextView && child.text.isNullOrEmpty() && !emptyText.isNullOrEmpty()) { child.text = emptyText - }else if(child is ImageView && emptyIcon!=0){ + }else if(child is ImageView && child.drawable==null && emptyIcon!=0){ child.setImageResource(emptyIcon) } }