Skip to content

Commit eaa93ec

Browse files
committed
Update
1 parent 8eca0ba commit eaa93ec

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

app/src/main/java/com/omarea/common/ui/BannerNotificationManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.os.Looper
77
import android.view.Gravity
88
import android.view.LayoutInflater
99
import android.view.View
10-
import android.view.ViewGroup
1110
import android.widget.ImageView
1211
import android.widget.TextView
1312
import android.widget.Toast
@@ -112,12 +111,13 @@ object BannerNotificationManager {
112111
}
113112
messageView.text = req.message
114113

115-
// Toast mặc định wrap_content theo nội dung -> ép chiều rộng gần bằng màn hình
116-
// (trừ lề 2 bên) để có dáng banner tràn ngang như mong muốn.
114+
// Toast luôn tự set kích thước cửa sổ kiểu wrap_content theo nội dung, gán layoutParams
115+
// cho view KHÔNG có tác dụng ép độ rộng (window cha quyết định MeasureSpec, không phải
116+
// layoutParams của view con). Phải dùng minimumWidth để ép độ rộng tối thiểu khi tự đo.
117117
val density = activity.resources.displayMetrics.density
118118
val marginPx = (12 * density).toInt()
119119
val screenWidth = activity.resources.displayMetrics.widthPixels
120-
view.layoutParams = ViewGroup.LayoutParams(screenWidth - marginPx * 2, ViewGroup.LayoutParams.WRAP_CONTENT)
120+
view.minimumWidth = screenWidth - marginPx * 2
121121

122122
val toast = Toast(activity.applicationContext)
123123
toast.duration = Toast.LENGTH_LONG

0 commit comments

Comments
 (0)